C
C *** LAST REVISED ON 15-MAR-1988 08:38:38.00
C *** SOURCE FILE: [DL.GRAPHICS.LONGLIB]MLIB.FOR
C
C ************************************************************************
C
C	MASTER PLOTTING SUBROUTINES FOR THE LONGLIB GRAPHICS LIBRARY
C	CREATED BY DGL AT JPL
C	INCLUDED IN LONGLIB GRAPHICS LIBRARIES
C
C ************************************************************************
C
	SUBROUTINE PLOTLG(X,Y,NP,IFLAG,XAXL,YAXL,XTITL,NXT,
     1		YTITL,NYT,TITLE,NT,XMIN,XMAX,YMIN,YMAX,ICOL,ILINE)
C
C	CREATED BY D. LONG    OCT, 1983	AT JPL
C	MODIFIED BY D. LONG   FEB, 1986 AT JPL  + ADDED LINE TYPE
C
C	MASTER ROUTINE TO PLOT A LINE OF DATA IN LOG/LINEAR COMBINATION
C
C	X	REAL X VALUE ARRAY
C	Y	REAL Y DATA ARRAY
C	NP	INT  # OF POINTS IN ARRAY
C	IFLAG	INT
C	  (MAG) >10000 REPEAT PLOTTING BUT DO NOT INTIALIZE PLOTTER
C		< 0  REPEAT PLOTTING (DON'T CLOSE PLOTTER OUTPUT)
C		= 0  CLOSE PLOTTER OUTPUT--DO NOT PRODUCE PLOT
C		> 0  SINGLE PLOT OUTPUT ONLY (PLOTTER OUTPUT CLOSED)
C	  (ONE'S DIGIT) = 1 X LINEAR, Y LOGRITHMIC (BASE 10)
C	  (ONE'S DIGIT) = 2 X LOGRITHMIC,Y LINEAR
C	  (ONE'S DIGIT) = 3 X LOGRITHMIC,Y LOGRITHMIC
C	  (ONE'S DIGIT) = 4 X LINEAR, Y LINEAR
C	  (TEN'S DIGIT) = 0 NO GRID OR AXIS
C	  (TEN'S DIGIT) = 1 PLOT BOX WITH AXIS TICKS
C	  (TEN'S DIGIT) = 2 PLOT SOLID CARTESIAN GRID
C	  (TEN'S DIGIT) = 3 PLOT TICKED CARTESIAN GRID W/O BOX
C	  (TEN'S DIGIT) = 4 PLOT TICKED CARTESIAN GRID WITH BOX
C	  (TEN'S DIGIT) = 5 PLOT BOX WITH AXIS TICKS AND TICKED CARTESIAN GRID
C	  (TEN'S DIGIT) = 6 PLOT W/O BOX OR GRID BUT INCLUDE AXISES
C	  (TEN'S DIGIT) = 7 PLOT SOLID LOGARITHMIC GRID 
C	  (TEN'S DIGIT) = 8 PLOT DOTTED LOGARITHMIC GRID 
C	  (TEN'S DIGIT) = 9 PLOT TICKED LOGARITHMIC GRID 
C     (HUNDRED'S DIGIT) = 0 ASK WHICH SCREEN DEVICE TO USE
C			<>0 SCREEN DEVICE CODE
C	XAXL	REAL  X AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C	YAXL	REAL  Y AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C NOTE: 	XMIN,XMAX,YMIN,YMAX ARE ONLY REQUIRED IF XAXL OR YAXL < 0
C
C	XTITL	CHAR  X AXIS TITLE
C	NXT	INT   NUMBER OF CHARACTERS IN X AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	YTITL	CHAR  Y AXIS TITLE
C	NYT	INT   NUMBER OF CHARACTERS IN Y AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	TITLE	CHAR  PLOT TITLE
C	NT	INT   NUMBER OF CHARACTERS IN PLOT TITLE (<100)
C		= 0  NO TITLE
C		< 0  USE COLOR ARRAY (REQUIRES XMIN,XMAX,YMIN,YMAX TOO)
C			IF ABS(NT)/100 > 0 USE LINE TYPE
C	XMIN	REAL  MINIMUM VALUE DISPLAYED ON X AXIS
C	XMAX	REAL  MAXIMUM VALUE DISPLAYED ON X AXIS
C	YMIN	REAL  MINIMUM VALUE OF Y ARRAY
C	YMAX	REAL  MAXIMUM VALUE OF Y ARRAY
C	ICOL	INT   ARRAY OF PEN COLORS DIMENSIONED 4
C			ICOL(1) = GRID COLOR
C			ICOL(2) = AXIS LINE COLOR
C			ICOL(3) = AXIS NUMBERS COLOR
C			ICOL(4) = AXIS TITLE COLOR
C			ICOL(5) = AXIS EXPONENT COLOR
C			ICOL(6) = LINE COLOR
C			ICOL(7) = TITLE COLOR (COLOR UPON RETURN)
C	ILINE	INT  LINE TYPE FOR PLOTTED LINE
C
	INTEGER XTITL(1),YTITL(1),TITLE(1)
	REAL Y(NP),X(NP),PY(2)
	LOGICAL REPEAT
	INTEGER PL,ICOL(7),IC(4)
	COMMON /CPLOTLG/XM,DX,YM,DY
	DATA REPEAT/.FALSE./
	PL=3					!PRINTER DATA FILE= FOR003.DAT
	IF (IFLAG.EQ.0) THEN
		IF (REPEAT) CALL PLOTND !CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
		RETURN
	ENDIF
	JF=IABS(IFLAG)
	IF (.NOT.REPEAT.AND.JF.LT.10000) THEN
		ILU=-(JF/100)			!SCREEN DEVICE, CLEAR SCREEN
		CALL FRAME(PL,ILU,1.2,1.2,1.)	!INTIALIZE PLOT PACKAGE
	ELSE
		CALL CTERM(-1)			!RESTORE PLOT MODE
C		CALL NEWPAGE			!NEW PAGE
		JF=MOD(JF,100)
	ENDIF
	JF=MOD(JF,100)
	IF=JF
	IF (IF.GT.10) IF=MOD(IF,10)
	JF=JF-IF
	NX=ABS(ANINT(XAXL))				!GRID SIZES
	NY=ABS(ANINT(YAXL))
	IF (IF.EQ.2.OR.IF.EQ.3) THEN
		CALL SCALG(X,ABS(XAXL),NP,1,1,XM,DX)	!SMOOTH SCALE FACTORS
		IK=-1
		GDX=1./DX
		NX=DX*ABS(XAXL)
		INX=-1
	ELSE
		CALL SCALE(X,ABS(XAXL),NP,1,1,XM,DX)	!SMOOTH SCALE FACTORS
		IK=0
		GDX=1.
		INX=1
	ENDIF
	IF (XAXL.LT.0.0) THEN				!INPUT SCALING
		IF (IF.EQ.2.OR.IF.EQ.3) THEN
			XM=ALOG10(ABS(XMIN)+1.E-25)
			IF (XM.NE.AINT(XM)) XM=AINT(XM)-1.
			DX=AINT(ALOG10(ABS(XMAX)+1.E-25))+1.
			DX=(DX-XM)/ABS(XAXL)
			GDX=1./DX
			NX=DX*ABS(XAXL)
		ELSE
			XM=XMIN
			DX=(XMAX-XMIN)/ABS(XAXL)
			GDX=1.
		ENDIF
	ENDIF
	IF (IF.EQ.1.OR.IF.EQ.3) THEN
		CALL SCALG(Y,ABS(YAXL),NP,1,1,YM,DY)	!SMOOTH SCALE FACTORS
		IK=-1+IK
		GDY=1./DY
		NY=DY*ABS(YAXL)
		INY=-1
	ELSE
		CALL SCALE(Y,ABS(YAXL),NP,1,1,YM,DY)	!SMOOTH SCALE FACTORS
		IK=1+IK
		GDY=1.
		INY=1
	ENDIF
	IF (YAXL.LT.0.0) THEN				!INPUT SCALING
		IF (IF.EQ.1.OR.IF.EQ.3) THEN
			YM=ALOG10(ABS(YMIN)+1.E-25)
			IF (YM.NE.AINT(YM)) YM=AINT(YM)-1.
			DY=AINT(ALOG10(ABS(YMAX)+1.E-25))+1.
			DY=(DY-YM)/ABS(YAXL)
			GDY=1./DY
			NY=DY*ABS(YAXL)
		ELSE
			YM=YMIN
			DY=(YMAX-YMIN)/ABS(YAXL)
			GDY=1.
		ENDIF
	ENDIF
	IF (JF.EQ.0) GOTO 77		!NO AXIS
	IF (JF.EQ.60) GOTO 76		!NO GRID
	IF (JF.GT.60) THEN		!LOGRITHMIC GRID
		II=0
		IF (JF.EQ.70) II=1
		IF (JF.EQ.80) II=2
		CALL LGRID(0.,0.,GDX,GDY,INX*NX,INY*NY,II)
		GOTO 76
	ENDIF
	IF (JF.GE.20) THEN		!CARTESIAN GRID
		IF (JF.GE.30) NX=-NX
		IF (JF.GE.40) NY=-NY
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(1)),0.,0) ! PEN COLOR
		CALL GRID(0.,0.,GDX,GDY,NX,NY)		!PRODUCE GRID
		IF (JF.EQ.50) JF=10
	ENDIF
76	NADD=0
	IF (NT.LT.0) THEN
		NADD=100000		! COLOR AXIS
		IC(1)=ICOL(2)
		IC(2)=ICOL(3)
		IC(3)=ICOL(4)
		IC(4)=ICOL(5)
	ENDIF
	IX=IABS(NXT)
	XL=ABS(XAXL)*SIGN(1.,FLOAT(NXT))		!AXIS LENGTH WITH TICK INFOR
	IF (NXT.NE.0) THEN
		IF (IF.EQ.2.OR.IF.EQ.3) THEN
		CALL LGAXS(0.,0.,XTITL,-IX-NADD,XL,0.,XM,DX,IC) !X-AXIS
		IF (JF.EQ.10) CALL LGAXS(0.,ABS(YAXL),XTITL,IX+100+NADD,
     $			XL,0.,XM,DX,IC) !X-AXIS
		ELSE
		CALL AXIS(0.,0.,XTITL,-IX-NADD,XL,0.,XM,DX,N1,N2,IC)  !X-AXIS
		IF (JF.EQ.10) CALL AXIS(0.,ABS(YAXL),XTITL,IX+100+NADD,
     $			XL,0.,XM,DX,N1,N2,IC)  !X-AXIS
		ENDIF
	ENDIF
	IY=IABS(NYT)+1000
	YL=ABS(YAXL)*SIGN(1.,FLOAT(NYT))
	IF (NYT.NE.0) THEN
		IF (IF.EQ.1.OR.IF.EQ.3) THEN
		CALL LGAXS(0.,0.,YTITL,IY+NADD,YL,90.,YM,DY,IC) !Y-AXIS
		IF (JF.EQ.10) CALL LGAXS(ABS(XAXL),0.,YTITL,-IY-100-NADD,
     $			YL,90.,YM,DY,IC) !Y-AXIS
		ELSE
		CALL AXIS(0.,0.,YTITL,IY+NADD,YL,90.,YM,DY,N1,N2,IC)  !Y-AXIS
		IF (JF.EQ.10) CALL AXIS(ABS(XAXL),0.,YTITL,-IY-100-NADD,
     $			YL,90.,YM,DY,N1,N2,IC)	!Y-AXIS
		ENDIF
	ENDIF
77	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6)),0.,0)	!PEN COLOR
	IF (IABS(NT)/100.GT.0) CALL NEWPEN(ILINE)	!LINE TYPE
	IF (IK.EQ.1) THEN
		CALL LINE(X,Y,NP,1,0,0,1,1,XM,DX,YM,DY) !PLOT DATA
	ELSE
		IF (IK.EQ.-1) IK=1				!CORRECT FLAG
		IF (IK.EQ.0) IK=-1
		CALL LGLIN(X,Y,NP,1,0,0,IK,1,1,XM,DX,YM,DY)	!PLOT DATA
	ENDIF
	IF (IABS(NT)/100.GT.0) CALL NEWPEN(0)		!RESTORE LINE TYPE
	CS=.21						!TITLE CHARACTER SIZE
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(7)),0.,0)	!PEN COLOR
	IF (NT.NE.0.AND.JF.NE.0) THEN			!PLOT TITLE
		XP=0.0
		YP=0.0
		CALL SYMBOL(XP,YP,CS,TITLE,
     $			0.,MOD(IABS(NT),100),-3)	!TITLE LENGTH
		XP=ABS(XAXL/2.)-XP/2.
		IF (XP.LT.0.) XP=0.
		CALL SYMBOL(XP,ABS(YAXL)+.15,CS,TITLE,
     $			0.,MOD(IABS(NT),100),-1)!PLOT TITLE
	ENDIF
	CALL PLOT(0.,0.,3)				!PEN UP
	IF (IFLAG.GT.0) THEN
		CALL CTERM(2)				!ASK IF CLEAR SCREN
		CALL PLOTND				!CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
	ENDIF
	IF (IFLAG.LT.0) THEN
		REPEAT=.TRUE.
		CALL CTERM(1)				!RETURN TO TEXT MODE
	ENDIF
	RETURN
	END
C
C *************************************************************************
C
	SUBROUTINE PHIST(A,NPTS,TITLE,NT,XL,YL,SUB,NS,XLABEL,
     $		NX,XMIN,XMAX,AMAX,IFLAG,ISHAD,AMEAN,SIGMA,ICOL)
C
C	CREATED BY D. LONG    AUG, 1983	AT JPL
C
C	GENERALIZED ROUTINE TO PLOT HISTOGRAMS
C
C	A	REAL	ARRAY CONTAINING HEIGHT OF HISTOGRAM COLUMNS
C	NPTS	INT	NUMBER OF POINTS IN A
C	TITLE	CHAR	TITLE OF HISTOGRAM
C	NT	INT	NUMBER OF CHARACTERS IN TITLE STRING
C			< 0 USE COLOR ARRAY
C	XL	REAL	LENGTH OF X AXIS
C	YL	REAL	LENGTH OF Y AXIS
C	SUB	CHAR	SUBTITLE OF HISTOGRAM
C	NS	INT	NUMBER OF CHARACTERS IN SUB STRING
C	XLABEL	CHAR	X AXIS LABEL OF HISTOGRAM
C	NX	INT	NUMBER OF CHARACTERS IN XLABEL STRING
C	XMIN	REAL	MINIMUM VALUE TO BE PLOTTED ON X AXIS
C	XMAX	REAL	MAXIMUM VALUE TO BE PLOTTED ON X AXIS
C	AMAX	REAL	MAXIMUM VALUE IN ARRRAY
C	IFLAG	INT	FUNCTION CONTROL FLAG
C			>10000	REPEAT PLOTTING BUT DO NOT INTIALIZE PLOTTER
C			< 0	REPEAT PLOTTING (DON'T CLOSE PLOTTER OUTPUT)
C			= 0	CLOSE PLOTTER OUTPUT--DO NOT PRODUCE PLOT
C			> 0	SINGLE PLOT OUTPUT ONLY (PLOTTER OUTPUT CLOSED)
C		ONE'S DIGIT = 2 PLOT A VALUE ATOP HISTOGRAM COLUMN
C			    = 1 DO NOT PLOT NUMBERS
C			    = 0 DO NOT PLOT AXISES
C		TEN'S DIGIT     SCREEN DEVICE CONTROL
C			    = 0 ASK SCREEN DEVICE TYPE
C	ISHAD	INT	SHADING CONTROL FLAG
C			< 0	SHADE WITH SOLID LINE
C			= 0	NO SHADING
C			> 0	SHADE WITH LINE TYPE ISHAD
C	AMEAN	REAL	LINE INDICATING MEAN (IN UNITS OF XMIN, XMAX)
C	SIGMA	REAL	LINES INDICATING 1 SIGMA DEVIATIONS FROM MEAN
C			> 0	MEAN AND SIGMA VALUES PLOTTED
C			= 0	ONLY MEAN VALUE PLOTTED
C			< 0	MEAN AND SIGMA VALUES NOT PLOTTED
C	ICOL	INT	PEN COLOR LIST (REQUIRED ONLY IF NT < 0
C			ICOL(1) AXIS LINE COLOR
C			ICOL(2) AXIS NUMBERS COLOR
C			ICOL(3) AXIS TITLE COLOR
C			ICOL(4) AXIS EXPONENT COLOR
C			ICOL(5) TITLE COLOR
C			ICOL(6) SUBTITLE COLOR
C			ICOL(7) MEAN MARK COLOR
C			ICOL(8) SIGMA MARK COLOR
C			ICOL(9) HISTOGRAM COLUMN COLORS (RETURN COLOR)
C			ICOL(10) HISTOGRAM COLUM LABEL COLOR
C
	DIMENSION A(NPTS),W(15),XS(5),YS(5),ISH(10),ICOL(1),IC(4)
	INTEGER TITLE(1),SUB(1),XLABEL(1)
	LOGICAL REPEAT
	COMMON /CPHIST/XM,DX,YM,DY
	DATA REPEAT/.FALSE./,XORG/1./,YORG/1.1/,YLEN/4./XLEN/7./
	DATA CS/.2/,CST/.25/,CSM/.14/				! TITLE SIZES
	DATA T/.2/,T1/.1/					! TICK SIZES
C
	IF (IFLAG.EQ.0) THEN
		IF (REPEAT) CALL PLOTND 	! CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
		RETURN
	ENDIF
	XLEN=ABS(XL)
	YLEN=ABS(YL)
	IF (XLEN.EQ.0..OR.YLEN.EQ.0.) RETURN	! ERROR RETURN
	JF=IABS(IFLAG)
	IF (.NOT.REPEAT.AND.JF.LT.10000) THEN
		ILU=-JF/10
		CALL FRAME(3,ILU,XORG,YORG,1.)		! OPEN PLOT OUTPUT
	ELSE
		CALL CTERM(-1)				! RETURN SCREEN TO GRAPHICS
C		CALL NEWPAGE				! START NEW PAGE
		JF=MOD(JF,10)
	ENDIF
	JF=MOD(JF,10)
	M=0
	IF (ISHAD.GT.0.AND.ISHAD.LT.11) M=ISHAD		! SELECT SHADE LINE TYPE
	IFLG=MOD(IABS(IFLAG),10)
	YM=0.						! BOTTOM Y AXIS
	DY=(AMAX-YM)/YLEN				! Y SCALE FACTOR
	NADD=0
	IF (NT.LT.0) THEN
		NADD=100000				! COLOR AXIS
		IC(1)=ICOL(1)
		IC(2)=ICOL(2)
		IC(3)=ICOL(3)
		IC(4)=ICOL(4)
	ENDIF
	IF (JF.NE.0) CALL AXIS(0.,0.,' ',1001+NADD,YLEN,
     $			90.,YM,DY,N1,N2,IC)	! PLOT Y AXIS
	NNX=NX
	IF (NNX.LT.1) NNX=1
	DX=(XMAX-XMIN)/XLEN
	XM=XMIN
	IF (JF.NE.0) CALL AXIS(0.,0.,XLABEL,-NNX-NADD,
     $			XLEN,0.,XM,DX,N1,N2,IC)	! PLOT X AXIS
	XP=0.
	YP=YLEN+CS+CSM+.25
	IF (JF.NE.0) THEN
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(5)),0.,0)	! PEN COLOR
	IF (NT.NE.0) CALL SYMBOL(XP,YP,CST,TITLE,0.,IABS(NT),-1)! TITLE
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6)),0.,0)	! PEN COLOR
	IF (NS.GT.0) CALL SYMBOL(XP,YP-CS-.05,CS,SUB,0.,NS,-1)	! SUBTITLE
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(7)),0.,0)	! PEN COLOR
	IF (SIGMA.GE.0.0) THEN				! PLOT MEAN
		X1=(AMEAN-XMIN)/DX			! LOCATE MEAN
		Y0=0.
		Y1=YLEN+CSM
		X2=X1-1.5*CSM
		CALL PLOT(X1-T1,Y0-T1,3)		! START TICK MARK
		CALL PLOT(X1,Y0,2)			! CENTER TICK MARK
		CALL PLOT(X1+T1,Y0-T1,2)		! END TICK MARK
		CALL PLOT(X1,Y0-T1,3)			! START LINE
		CALL PLOT(X1,Y1,2)			! END LINE
		CALL PLOT(X1-T,Y1,3)			! PUT ON HAT
		CALL PLOT(X1+T,Y1,2)			! END HAT
		CALL SYMBOL(X2,Y1+.05,CSM,'MEAN',0.,4,-1)
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(8)),0.,0)	! PEN COLOR
		IF (SIGMA.GT.0.0) THEN			! PLOT SIGMA
			Y1=Y1-CSM-.05
			X2=(AMEAN-SIGMA-XMIN)/DX	! MEAN - SIGMA
			X3=(AMEAN+SIGMA-XMIN)/DX	! MEAN + SIGMA
			X4=2.1*CSM
			CALL PLOT(X2-T1,Y0-T1,3)	! START TICK MARK
			CALL PLOT(X2,Y0,2)		! CENTER TICK MARK
			CALL PLOT(X2+T1,Y0-T1,2)	! END TICK MARK
			CALL PLOT(X2,Y0-T1,3)		! START LINE
			CALL PLOT(X2,Y1,2)		! END LINE
			CALL PLOT(X2-T,Y1,3)		! PUT ON HAT
			CALL PLOT(X2+T,Y1,2)		! END HAT
			CALL SYMBOL(X2-X4,Y1+.05,CSM,'SIGMA',0.,5,-1)
			CALL PLOT(X3-T1,Y0-T1,3)	! START TICK MARK
			CALL PLOT(X3,Y0,2)		! CENTER TICK MARK
			CALL PLOT(X3+T1,Y0-T1,2)	! END TICK MARK
			CALL PLOT(X3,Y0-T1,3)		! START LINE
			CALL PLOT(X3,Y1,2)		! END LINE
			CALL PLOT(X3-T,Y1,3)		! PUT ON HAT
			CALL PLOT(X3+T,Y1,2)		! END HAT
			CALL SYMBOL(X3-X4,Y1+.05,CSM,'SIGMA',0.,5,-1)
		ENDIF
	ENDIF
	ENDIF
C
	WIDTH=XLEN/FLOAT(NPTS)
	CW=WIDTH-.02
	IF (CW.LT.0.) CW=WIDTH
	IF (WIDTH.GT.0.18) CW=0.18
	ANG=45.
	X0=0.
	Y0=YM
	X1=WIDTH/2.-CW/2.
C
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(9)),0.,0)	! PEN COLOR
	DO 100 I=1,NPTS
		Y1=(A(I)-YM)/DY
		XS(1)=X0
		YS(1)=Y0+.02
		XS(2)=X0
		YS(2)=Y1
		CALL RECT(X0,Y0,X0+WIDTH,Y1)		! PLOT HISTOGRAM
		X0=X0+WIDTH
		XS(3)=X0
		YS(3)=Y1
		XS(4)=X0
		YS(4)=Y0+.02
		IF (IFLG.EQ.2) THEN
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(10)),0.,0)	! PEN COLOR
			CALL NUMBER(X0-X1,Y1+.08,CW,
     $					A(I),90.,-1,-1)
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(9)),0.,0)	! PEN COLOR
		ENDIF
		IF (M.NE.0.AND.Y1.GT..02) THEN		! ADD SHADING
			CALL SHADE(XS,YS,4,1,2,.06,ANG,W,M,0.,1.,0.,1.)
			IF (ANG.EQ.45.) THEN		! ALTERNATE ANGLES
				ANG=135.
			ELSE
				ANG=45.
			ENDIF
		ENDIF
100	CONTINUE
	CALL PLOT(0.,0.,3)
	IF (IFLAG.GT.0) THEN
		CALL CTERM(2)				!ASK IF CLEAR SCREEN
		CALL PLOTND				!CLOSE PLOTTER
		REPEAT=.FALSE.
	ENDIF
	IF (IFLAG.LT.0) THEN
		REPEAT=.TRUE.
		CALL CTERM(1)				!PUT TERMINAL IN TEXT MODE
	ENDIF
	RETURN
	END
C
C *************************************************************************
C
	SUBROUTINE PLOTSC(X,Y,NP,IFLAG,XAXL,YAXL,XTITL,NXT,
     1		YTITL,NYT,TITLE,NT,XMIN,XMAX,YMIN,YMAX,ICOL,ILINE)
C
C	CREATED BY D. LONG    OCT, 1983	AT JPL
C	MODIFIED BY D. LONG   FEB, 1986 AT JPL + ADDED LINE TYPE
C
C	ROUTINE TO PLOT A LINE OF DATA
C
C	X	REAL X VALUE ARRAY
C	Y	REAL Y DATA ARRAY
C	NP	INT  # OF POINTS IN ARRAY
C	IFLAG	INT
C	 (MAG)	>10000 REPEAT PLOTTING BUT DO NOT INTIALIZE PLOTTER
C		< 0  REPEAT PLOTTING (DON'T CLOSE PLOTTER OUTPUT)
C		= 0  CLOSE PLOTTER OUTPUT--DO NOT PRODUCE PLOT
C		> 0  SINGLE PLOT OUTPUT ONLY (PLOTTER OUTPUT CLOSED)
C (ONE'S DIGIT) =0  DO NOT PLOT AXISES OR TITLE
C 		=1  PLOT BOX WITH AXIS TICK MARKS
C		=2  PLOT A SOLID GRID
C		=3  PLOT TICKED GRID W/O BOX
C		=4  PLOT TICKED GRID WITH BOX
C		=5  PLOT BOX WITH AXIS TICK MARKS AND TICKED GRID
C		=6  PLOT WITH NO BOX OR GRID
C (TEN'S DIGIT) =0  ASK WHICH SCREEN DEVICE TO USE
C		<>0 SCREEN DEVICE CODE
C	XAXL	REAL  X AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C	YAXL	REAL  Y AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C NOTE: 	XMIN,XMAX,YMIN,YMAX ARE ONLY REQUIRED IF XAXL OR YAXL < 0
C
C	XTITL	CHAR  X AXIS TITLE
C	NXT	INT   NUMBER OF CHARACTERS IN X AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	YTITL	CHAR  Y AXIS TITLE
C	NYT	INT   NUMBER OF CHARACTERS IN Y AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	TITLE	CHAR  PLOT TITLE
C	NT	INT   NUMBER OF CHARACTERS IN PLOT TITLE (<100)
C		= 0  NO TITLE
C		< 0  USE PEN COLOR ARRAY (XMIN-YMAX ALSO REQUIRED)
C			IF ABS(NT)/100 > 0 USE LINE TYPE
C	XMIN	REAL  MINIMUM VALUE DISPLAYED ON X AXIS
C	XMAX	REAL  MAXIMUM VALUE DISPLAYED ON X AXIS
C	YMIN	REAL  MINIMUM VALUE OF Y ARRAY
C	YMAX	REAL  MAXIMUM VALUE OF Y ARRAY
C	ICOL	INT   PEN COLOR CONTROL ARRAY (REQUIRED ONLY IF NT < 0)
C			ICOL(1) GRID COLOR
C			ICOL(2) AXIS LINE COLOR
C			ICOL(3) AXIS NUMBERS COLOR
C			ICOL(4) AXIS LABEL COLOR
C			ICOL(5) AXIS EXPONENT COLOR
C			ICOL(6) PLOTTED LINE COLOR
C			ICOL(7) TITLE COLOR (RETURN COLOR)
C	ILINE	INT  LINE TYPE OF PLOTTED LINE
C
	INTEGER XTITL(1),YTITL(1),TITLE(1)
	REAL Y(NP),X(NP),PY(2)
	LOGICAL REPEAT
	INTEGER PL,ICOL(1),IC(4)
	COMMON /CPLOTSC/XM,DX,YM,DY
	DATA REPEAT/.FALSE./
	PL=3					!PRINTER DATA FILE= FOR003.DAT
	IF (IFLAG.EQ.0) THEN
		IF (REPEAT) CALL PLOTND !CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
		RETURN
	ENDIF
	JF=IABS(IFLAG)
	IF (.NOT.REPEAT.AND.JF.LT.10000) THEN
		ILU=-(JF/10)
		CALL FRAME(PL,ILU,1.2,1.2,1.)	!INTIALIZE PLOT PACKAGE
	ELSE
		CALL CTERM(-1)			!RESTORE PLOT MODE
C		CALL NEWPAGE			!NEW PAGE
		JF=MOD(JF,10)
	ENDIF
	JF=MOD(JF,10)
	NX=ABS(ANINT(XAXL))			!GRID SIZES
	NY=ABS(ANINT(YAXL))
	CALL SCALE(X,ABS(XAXL),NP,1,1,XM,DX)	!SMOOTH SCALE FACTORS
	IF (XAXL.LT.0.0) THEN			!INPUT SCALE FACTORS
		XM=XMIN
		DX=(XMAX-XMIN)/ABS(XAXL)
	ENDIF
	CALL SCALE(Y,ABS(YAXL),NP,1,1,YM,DY)	!SMOOTH SCALE FACTORS
	IF (YAXL.LT.0.0) THEN			!INPUT SCALE FACTORS
		YM=YMIN
		DY=(YMAX-YMIN)/ABS(YAXL)
	ENDIF
	IF (JF.EQ.0) GOTO 77
	IF (JF.EQ.6) GOTO 76
	IF (JF.GT.1) THEN			!GRID
		IF (JF.GE.3) NX=-NX		!TICKED GRID
		IF (JF.GT.4) NY=-NY		!BOXED TICKED GRID
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(1)),0.,0)! PEN COLOR
		CALL GRID(0.,0.,1.,1.,NX,NY)	!PLOT GRID
		IF (JF.EQ.5) JF=1
	ENDIF
76	IX=IABS(NXT)
	XL=ABS(XAXL)*SIGN(1.,FLOAT(NXT))
	NADD=0
	IF (NT.LT.0) THEN
		IC(1)=ICOL(2)
		IC(2)=ICOL(3)
		IC(3)=ICOL(4)
		IC(4)=ICOL(5)
		NADD=100000		! PEN COLOR
	ENDIF
	IF (NXT.NE.0) THEN
		CALL AXIS(0.,0.,XTITL,-IX-NADD,XL,0.,XM,DX,
     $			ND1,ND2,IC) !X-AXIS
	IF (JF.EQ.1) CALL AXIS(0.,ABS(YAXL),XTITL,IX+100+NADD,XL,0.,XM,DX,
     $			ND1,ND2,IC) !X-AXIS
	ENDIF
	IY=IABS(NYT)+1000
	YL=ABS(YAXL)*SIGN(1.,FLOAT(NYT))
	IF (NYT.NE.0) THEN
		CALL AXIS(0.,0.,YTITL,IY+NADD,YL,90.,YM,DY,ND1,ND2,IC) !Y-AXIS
		IF (JF.EQ.1) CALL AXIS(ABS(XAXL),0.,YTITL,-IY-100-NADD,
     $			YL,90.,YM,DY,ND1,ND2,I) 	!Y-AXIS
	ENDIF
77	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6)),0.,0)	!PEN COLOR
	IF (IABS(NT)/100.GT.0) CALL NEWPEN(ILINE)	!LINE TYPE
	CALL LINE(X,Y,NP,1,0,0,1,1,XM,DX,YM,DY) 	!PLOT DATA
	CS=.21						!TITLE CHARACTER SIZE
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(7)),0.,0)	!PEN COLOR
	IF (IABS(NT)/100.GT.0) CALL NEWPEN(0)		!LINE TYPE
	IF (NT.NE.0.AND.JF.NE.0) THEN			!PLOT TITLE
		XP=0.
		YP=0.
		CALL SYMBOL(XP,YP,CS,TITLE,
     $			0.,MOD(IABS(NT),100),-3)	!TITLE LENGTH
		XP=ABS(XAXL/2.)-XP/2.
		IF (XP.LT.0.) XP=0.
		CALL SYMBOL(XP,ABS(YAXL)+.15,CS,TITLE,
     $			0.,MOD(IABS(NT),100),-1)	!PLOT TITLE
	ENDIF
	CALL PLOT(0.,0.,3)				!PEN UP
	IF (IFLAG.GT.0) THEN
		CALL CTERM(2)				!ASK IF CLEAR SCREEN
		CALL PLOTND				!CLOSE PLOTTER
		REPEAT=.FALSE.
	ENDIF
	IF (IFLAG.LT.0) THEN
		REPEAT=.TRUE.
		CALL CTERM(1)				!TERMINAL TO TEXT MODE
	ENDIF
	RETURN
	END
C
C *************************************************************************
C
	SUBROUTINE PLOTSC2(X,Y,Y2,NP,IFLAG,XAXL,YAXL,XTITL,NXT,
     1			YTITL,NYT,TITLE,NT,XMIN,XMAX,YMIN,YMAX,ICOL)
C
C	CREATED BY D. LONG     OCT, 1983	AT JPL
C	REVISED BY D. LONG     FEB, 1986 -- ADDED CHANGE OF LINE TYPE
C					    FOR SECOND CURVE
C
C	ROUTINE TO PLOT TWO LINES OF DATA
C
C	X	REAL X VALUE ARRAY
C	Y	REAL Y DATA ARRAY
C	Y2	REAL Y DATA ARRAY
C	NP	INT  # OF POINTS IN ARRAY
C	IFLAG	INT
C	 (MAG)	>10000 REPEAT PLOTTING BUT DO NOT INTIALIZE PLOTTER
C		< 0   REPEAT PLOTTING (DON'T CLOSE PLOTTER OUTPUT)
C		= 0   CLOSE PLOTTER OUTPUT--DO NOT PRODUCE PLOT
C		> 0   SINGLE PLOT OUTPUT ONLY (PLOTTER OUTPUT CLOSED)
C (ONE'S DIGIT) =0  DO NOT PLOT AXISES OR TITLE
C 		=1  PLOT A BOX WITH AXIS TICKS
C		=2  PLOT A SOLID GRID
C		=3  PLOT A TICKED GRID W/O BOX
C		=4  PLOT A TICKED GRID WITH BOX
C		=5  PLOT A BOX WITH AXIS TICKS AND TICKED GRID
C		=6  PLOT W/O BOX OR GRID
C (TEN'S DIGIT) =0  ASK ABOUT SCREEN DEVICE
C		<>0 SCREEN DEVICE CODE
C	XAXL	REAL  X AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C	YAXL	REAL  Y AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C NOTE: 	XMIN,XMAX,YMIN,YMAX ARE ONLY REQUIRED IF XAXL OR YAXL < 0
C
C	XTITL	CHAR  X AXIS TITLE
C	NXT	INT   NUMBER OF CHARACTERS IN X AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	YTITL	CHAR  Y AXIS TITLE
C	NYT	INT   NUMBER OF CHARACTERS IN Y AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	TITLE	CHAR  PLOT TITLE
C	NT	INT   NUMBER OF CHARACTERS IN PLOT TITLE (<100)
C		= 0  NO TITLE
C		< 0  USE PEN COLOR ARRAY
C			IF ABS(NT)/100 > 0 USE LINE TYPE
C	XMIN	REAL  MINIMUM VALUE DISPLAYED ON X AXIS
C	XMAX	REAL  MAXIMUM VALUE DISPLAYED ON X AXIS
C	YMIN	REAL  MINIMUM VALUE OF Y ARRAY
C	YMAX	REAL  MAXIMUM VALUE OF Y ARRAY
C	ICOL	INT   PEN COLOR CONTROL (REQUIRED ONLY IF NT < 0)
C			ICOL(1) GRID COLOR
C			ICOL(2) AXIS LINE COLOR
C			ICOL(3) AXIS NUMBERS COLOR
C			ICOL(4) AXIS TITLE COLOR
C			ICOL(5) AXIS EXPONENT COLOR
C			ICOL(6) LINE 1 COLOR
C			ICOL(7) LINE 2 COLOR
C			ICOL(8) TITLE COLOR (RETURN)
C
	INTEGER XTITL(1),YTITL(1),TITLE(1)
	REAL Y(NP),X(NP),Y2(NP),PY(2)
	LOGICAL REPEAT
	INTEGER PL,ICOL(1),IC(4)
	COMMON /CPLOTSC2/XM,DX,YM,DY
	DATA REPEAT/.FALSE./
	PL=3					!PRINTER DATA FILE= FOR003.DAT
	IF (IFLAG.EQ.0) THEN
		IF (REPEAT) CALL PLOTND !CLOSE PLOTTER
		REPEAT=.FALSE.
		RETURN
	ENDIF
	JF=IABS(IFLAG)
	IF (.NOT.REPEAT.AND.JF.LT.10000) THEN
		ILU=-JF/10
		CALL FRAME(PL,ILU,1.2,1.2,1.)	!INTIALIZE PLOT PACKAGE
	ELSE
		CALL CTERM(-1)			!RESTORE PLOT MODE ON TERMINAL
C		CALL NEWPAGE			!NEW PAGE
		JF=MOD(JF,10)
	ENDIF
	JF=MOD(JF,10)
	NX=ABS(ANINT(XAXL))			!GRID SIZES
	NY=ABS(ANINT(YAXL))
	CALL SCALE(X,ABS(XAXL),NP,1,1,XM,DX)	!SMOOTH SCALE FACTORS
	IF (XAXL.LT.0.0) THEN			!INPUT SCALING
		XM=XMIN
		DX=(XMAX-XMIN)/ABS(XAXL)
	ENDIF
	IF (YAXL.LT.0.0) THEN			!INPUT SCALING
		YM=YMIN
		DY=(YMAX-YMIN)/ABS(YAXL)
	ELSE
		YM=Y(1)
		YX=Y2(1)
		DO 5 I=2,NP
			YM=MIN(Y(I),Y2(I),YM)
			YX=MAX(Y(I),Y2(I),YX)
5		CONTINUE
		PY(1)=YM
		PY(2)=YX
		CALL SCALE(PY,ABS(YAXL),2,1,1,YM,DY)	!SMOOTH SCALE FACTORS
	ENDIF
	IF (JF.EQ.0) GOTO 77
	IF (JF.EQ.6) GOTO 76
	IF (JF.GT.1) THEN
		IF (JF.GE.3) NX=-NX
		IF (JF.GE.4) NY=-NY
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(1)),0.,0) !PEN COLOR
		CALL GRID(0.,0.,1.,1.,NX,NY)	!PRODUCE GRID
		IF (JF.EQ.5) JF=1
	ENDIF
76	IX=IABS(NXT)
	XL=ABS(XAXL)*SIGN(1.,FLOAT(NXT))
	NADD=0
	IF (NT.LT.0) THEN
		NADD=100000		 !PEN COLOR
		IC(1)=ICOL(2)
		IC(2)=ICOL(3)
		IC(3)=ICOL(4)
		IC(4)=ICOL(5)
	ENDIF
	IF (NXT.NE.0) THEN
		CALL AXIS(0.,0.,XTITL,-IX-NADD,XL,0.,XM,DX,N1,N2,IC) !X-AXIS
		IF (JF.EQ.1) CALL AXIS(0.,ABS(YAXL),XTITL,IX+100+NADD,
     $			XL,0.,XM,DX,N1,N2,IC) !X-AXIS
	ENDIF
	IY=IABS(NYT)+1000
	YL=ABS(YAXL)*SIGN(1.,FLOAT(NYT))
	IF (NYT.NE.0) THEN
		CALL AXIS(0.,0.,YTITL,IY+NADD,YL,90.,YM,DY,N1,N2,IC) !Y-AXIS
		IF (JF.EQ.1) CALL AXIS(ABS(XAXL),0.,YTITL,-IY-100-NADD,
     $			YL,90.,YM,DY,N1,N2,IC) 		!Y-AXIS
	ENDIF
C
77	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6)),0.,0) 	!PEN COLOR
	CALL NEWPEN(0)					!SET LINE TYPE
	CALL LINE(X,Y,NP,1,0,0,1,1,XM,DX,YM,DY)		!PLOT DATA
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(7)),0.,0)	!PEN COLOR
	CALL NEWPEN(3)					!CHANGE LINE TYPE
	CALL LINE(X,Y2,NP,1,0,0,1,1,XM,DX,YM,DY)	!PLOT DATA
	CALL NEWPEN(0)					!RESTORE LINE TYPE
	CS=.21						!TITLE CHARACTER SIZE
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(8)),0.,0)	!PEN COLOR
	IF (NT.NE.0.AND.JF.NE.0) THEN
		XP=0.0
		YP=0.0
		CALL SYMBOL(XP,YP,CS,TITLE,
     $			0.,IABS(NT),-3)			!TITLE LENGTH
		XP=ABS(XAXL/2.)-XP/2.
		IF (XP.LT.0.) XP=0.
		CALL SYMBOL(XP,ABS(YAXL)+.1,CS,TITLE,
     $			0.,IABS(NT),-1)			!PLOT TITLE
	ENDIF
	CALL PLOT(0.,0.,3)				!PEN UP
C
	IF (IFLAG.GT.0) THEN
		CALL CTERM(2)				!ASK IF CLEAR SCREEN
		CALL PLOTND				!CLOSE PLOTTER
		REPEAT=.FALSE.
	ENDIF
	IF (IFLAG.LT.0) THEN
		REPEAT=.TRUE.
		CALL CTERM(1)				!PUT TERMINAL TEXT MODE
	ENDIF
	RETURN
	END
C
C *************************************************************************
C
	SUBROUTINE VAX3D(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,IFLAG,IAXIS,
     $		XT,NXT,XASTART,XAEND,YT,NYT,ZT,NZT,ZASTART,ZAEND,
     $		AMININ,AMAXIN,ICOL)
C
C	CREATED BY D. LONG  MAR., 1984	AT JPL
C
C	SIMPLIFIES CALLING VAX3DX ROUTINE AXISES
C
	DIMENSION A(INX,INZ),ICOL(1)
	INTEGER XT(1),YT(1),ZT(1)
	IAX=MOD(IAXIS,10)
	IF (IAXIS.LT.0) THEN
		AMN=AMININ
		AMX=AMAXIN
	ENDIF
	IF (MOD(IFLAG,10).EQ.2) THEN
		CALL VAX3DX(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,IFLAG,IAX,
     $			XT,NXT,XASTART,XAEND,NMX,NNX,MLX,TSX,NDX,SMX,
     $			YT,NYT,NMY,NNY,MLY,TSY,NDY,SMY,
     $			ZT,NZT,ZASTART,ZAEND,NMZ,NNZ,MLZ,TSZ,NDZ,SMZ,
     $			AMN,AMX,ICOL)
	ELSE
		CALL VAX3DX(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,IFLAG,IAX,
     $			XT,NXT,XASTART,XAEND,NMX,NNX,MLX,TSX,NDX,SMX,
     $			YT,NYT,NMY,NNY,MLY,TSY,NDY,SMY,
     $			ZT,NZT,ZASTART,ZAEND,NMZ,NNZ,MLZ,TSZ,NDZ,SMZ,
     $			AMN,AMX,IC)
	ENDIF
	RETURN
	END
C
C
	SUBROUTINE VAX3DX(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,IFLAG,IAXIS,
     $		XT,NXT,XASTART,XAEND,NMX,NNX,MLX,TSX,NDX,SMX,
     $		YT,NYT,NMY,NNY,MLY,TSY,NDY,SMY,
     $		ZT,NZT,ZASTART,ZAEND,NMZ,NNZ,MLZ,TSZ,NDZ,SMZ,
     $		AMININ,AMAXIN,ICOL)
C
C	CREATED BY D. LONG     APR, 1984	AT JPL
C	REVISED BY D. LONG     MAY, 1986
C	+REDUCED REDUNDANT PEN MOTIONS AND CORRECTED SOME MINOR BUGS
C
C	ROUTINE TO PLOT DATA IN 3-D OVERLAY FORM
C
C	COORDINATE SYSTEM IS:		Y  Z
C				NAMES:	|/
C					 \X
C
C	A	REAL ARRAY A(INX,INZ) CONTAINING VERTICAL HEIGHT DATA
C	INX,INZ INTEGERS DIMENSION OF A ARRAY
C	NX,NZ	INTEGERS INDICATING SIZE OF A ARRAY TO PLOT
C	ALPHA	REAL ANGLE (IN DEGREES) OF X AXIS (NX) FROM HORIZONTAL
C	BETA	REAL ANGLE (IN DEGREES) OF Z AXIS (NZ) FROM HORIZONTAL
C	XH,YH,ZH REAL LENGTH OF EACH AXIS
C	IFLAG	INTEGER
C		>10000	REPEAT PLOTTING BUT DO NOT INTIALIZE PLOTTER
C		< 0	REPEAT PLOTTING (DON'T CLOSE PLOTTER OUTPUT
C		= 0	CLOSE PLOTTER OUTPUT--DO NOT PRODUCE PLOT
C		> 0	SINGLE PLOT OUTPUT ONLY (PLOTTER OUTPUT CLOSED)
C 	(ONE'S DIGIT) = 2 USE PEN COLOR CONTROL ARRAY
C		      = 1 DO NOT USE PEN COLOR ARRAY
C	(TEN'S DIGIT) = 0 PLOT SIDE PLATES
C		      = 1 DO NOT PLOT SIDE PLATES
C 	(HUNDREDS'S DIGIT) = 0 ASK WHICH SCREEN DEVICE TO USE
C		           <>0 SCREEN DEVICE CODE NUMBER
C 	IAXIS	INTEGER AXIS OPTION FLAG
C			= 0 DO NOT PLOT AXIS--FOLLOWING VARIABLES NOT REQUIRED
C			< 0 PLOT AXIS, USE INPUT Y AXIS SCALE--FOLLOWING VARIABLES REQUIRED
C			> 0 PLOT AXIS, USE COMPUTED Y AXIS SCALE--FOLLOWING VARIABLES REQUIRED
C 	(ONE'S DIGIT)	= 1 PLOT AXIS, Y AXIS SCALE--VARIABLES REQUIRED
C			= 2 PLOT AXIS, AUTO SCALE Y AXIS--VARIABLES REQUIRED
C	(TEN'S DIGIT)	= 0 DEFAULT AXIS PARAMETERS
C			= 1 SPECIALIZED AXIS2 PARAMETERS
C 	XT,YT,ZT	CHAR STRINGS FOR AXIS TITLES
C 	NXT,NYT,NZT	INT  LENGTH OF AXIS TITLES
C			     IF ZERO THEN THAT AXIS NOT PLOTTED
C 	XASTART,ZASTART	REAL AXIS START VALUES
C 	XAEND,ZAEND	REAL AXIS END VALUES
C FOLLOWING ONLY REQUIRED IF TEN'S DIGIT OF IFLAG=1
C	NMX,NMY,NMZ	INT NUMBER OF MINOR TICKS BETWEEN MAJOR TICKS
C	NNX,NNY,NNZ	INT HIGHLIGHT LENGTH OF NNX-TH MINOR TICK ON AXIS
C	MLX,MLY,MLZ	INT NUMBER OF MAJOR TICK MARKS ON AXIS
C	TSX,TSY,TSZ	REAL SIZE OF TITLE AND NUMBERS OF AXIS
C			  IF LESS THAN ZERO DO NOT AUTO-SCALE BY (x10^POWER)
C 	NDX,NDY,NDZ	INT NUMBER OF DIGITS TO RIGHT OF DECIMAL POINT
C 	SMX,SMY,SMZ	REAL MAJOR TICK LENGTH
C 	AMININ,AMAXIN 	REAL YAXIS SCALING FACTORS (ONLY NEEDED IF IAXIS < 0)
C	ICOL		INTEGER COLOR CONTROL (REQUIRED IF MAG(IFLAG)=2)
C			  ICOL(1) AXIS LINE COLOR
C			  ICOL(2) AXIS NUMBERS COLOR
C			  ICOL(3) AXIS TITLE COLOR
C			  ICOL(4) AXIS EXPONENT COLOR
C			  ICOL(5) PLOT COLOR
C
	DIMENSION A(INX,INZ),AS(2),ICOL(1),IC(4)
	PARAMETER (MAXSIZE=2048)
	DIMENSION H(MAXSIZE,2),P(MAXSIZE,2)
	INTEGER XT(1),YT(1),ZT(1)
	LOGICAL FLAG,HHIGH,REPEAT
	COMMON /LOCATE/ XSCALE,YSCALE,ZSCALE,AMIN,ALPH,BET
	DATA TPI/3.141592654/,REPEAT/.FALSE./
C
	IF (IFLAG.EQ.0) THEN
		IF (REPEAT) CALL PLOTND	!CLOSE PLOTTER
		REPEAT=.FALSE.
		RETURN
	ENDIF
	ALPH=ALPHA*TPI/180.		!X-AXIS INCLINATION 0-80 DEGS
	BET=BETA*TPI/180.		!Z-AXIS ANGLE 5-80 DEGS
C
	IF (IAXIS.LT.0) THEN
		AMAX=AMAXIN
		AMIN=AMININ
	ELSE
		AMAX=A(1,1)
		AMIN=A(1,1)
		DO 16IZ=1,NZ			!DETERMINE MAX,MIN ARRAY VALUES
			DO 16 IX=1,NX
				AMAX=AMAX1(AMAX,A(IX,IZ))
				AMIN=AMIN1(AMIN,A(IX,IZ))
16		CONTINUE
	ENDIF
	IF(ALPHA.LT.0..OR.ALPHA.GT.88..OR.BETA.LT.1..OR.BETA.GT.90.)THEN
		WRITE(*,3000)
3000		FORMAT(' *** VAX3DX INPUT ANGLE ERROR ***')
		RETURN
	ENDIF
	IF (AMAX.EQ.AMIN) THEN
		WRITE(*,3001)
3001		FORMAT(' *** VAX3DX SCALE ERROR *** MAX=MIN')
		AMAX=AMIN+1.
	ENDIF
C
	XLEN=ABS(XH)
	XSCALE=XLEN/FLOAT(NX-1)
	ZLEN=ABS(ZH)
	ZSCALE=ZLEN/FLOAT(NZ-1)
	YLEN=ABS(YH)
	IF (MOD(IABS(IAXIS),10).EQ.2) THEN	! SMOOTH SCALE FACTORS
		AS(1)=AMAX
		AS(2)=AMIN
		CALL SCALE(AS,YLEN,2,1,1,AMIN,DAA)
		AMAX=YLEN*DAA+AMIN
	ENDIF
	YSCALE=1.0
	IF (AMAX-AMIN.NE.0.0) YSCALE=YLEN/(AMAX-AMIN)
C
C	INTIALIZE PLOT PACKAGE
C
	JF=IABS(IFLAG)
	IF (.NOT.REPEAT.AND.JF.LT.10000) THEN
		ILU=JF/100
		CALL FRAME(3,ILU,1.5,0.65,1.)		!INTIALIZE
	ELSE
		CALL CTERM(-1)				!PUT TERMINAL PLOT MODE
	ENDIF
C
	IAF=IABS(IAXIS)/10
	JFF=MOD(JF,100)/100
	JF=MOD(JF,10)
	IF (IAXIS.NE.0) THEN		!PLOT AXIS LABELS
		NADD=0
		IF (JF.EQ.2) THEN
			IC(1)=ICOL(2)
			IC(2)=ICOL(3)
			IC(3)=ICOL(4)
			IC(4)=ICOL(5)
			NADD=100000	!PEN COLOR
		ENDIF
		CALL VXPT3D(XP,YP,AMIN,1,1,NX)
		DY=(AMAX-AMIN)/YLEN
		IF (NYT.GT.0) THEN 	!PLOT Y AXIS
			IF (IAF.EQ.1) THEN
				CALL AXIS2(XP,YP,YT,NYT+11000+NADD,
     $				YLEN,90.,AMIN,DY,NMY,NNY,-IABS(MLY),
     $				TSY,NDY,SMY,IC)
			ELSE
				CALL AXIS(XP,YP,YT,NYT+1000+NADD,
     $					YLEN,90.,AMIN,DY,N1,N2,IC)
			ENDIF
		ENDIF
		CALL VXPT3D(XP1,YP1,AMIN,NX,1,NX)
		DX=(XAEND-XASTART)/XLEN
		ANG=ATAN2(YP1-YP,XP1-XP)*180./TPI
		IF (NXT.GT.0) THEN
			IF (IAF.EQ.1) THEN
				CALL AXIS2(XP,YP,XT,-NXT-NADD-10000,XLEN,ANG,
     $				XASTART,DX,NMX,NNX,-IABS(MLX),TSX,NDX,SMX,IC)
			ELSE
				CALL AXIS(XP,YP,XT,-NXT-NADD,XLEN,ANG,
     $					XASTART,DX,N1,N2,IC)
			ENDIF
		ENDIF
		DZ=(ZAEND-ZASTART)/ZLEN
		IF (NZT.GT.0) THEN
			IF (IAF.EQ.1) THEN
				CALL AXIS2(XP1,YP1,ZT,-NZT-NADD-10000
     $				,ZLEN,BETA,ZASTART,DZ,NMZ,NNZ,
     $				-IABS(MLZ),TSZ,NDZ,SMZ,IC)
			ELSE
				CALL AXIS(XP1,YP1,ZT,-NZT-NADD,
     $				ZLEN,BETA,ZASTART,DZ,N1,N2,IC)
			ENDIF
		ENDIF
	ENDIF
	IF (JF.EQ.2) CALL PLOT(FLOAT(ICOL(5)),0.,0) !PEN COLOR
C
C	PLOT FRONT PLATE
C
	IPEN=3
	DO 14 I=1,NX
		IF (I.GT.MAXSIZE) GOTO 999
		CALL VXPT3D(H(I,1),H(I,2),A(I,1),I,1,NX) !INTIALIZE HISTORY
		CALL PLOT(H(I,1),H(I,2),IPEN)		 !PLOT SIDE LINE
		IPEN=2
14	CONTINUE
	IHOLD=NX
	IF (BETA.EQ.90.) GOTO 5
	IF (JFF.EQ.1) GOTO 71			! DON'T PLOT SIDE PLATES
	CALL VXPT3D(XP,YP,AMIN,NX,1,NX)
	CALL PLOT(XP,YP,2)
	DO 19 I=1,NX-1				!ADD SIDE LINES
		CALL PLOT(H(I,1),H(I,2),3)
		CALL VXPT3D(XP,YP,AMIN,I,1,NX)
		CALL PLOT(XP,YP,2)
		CALL VXPT3D(XP,YP,AMIN,I+1,1,NX)
		CALL PLOT(XP,YP,2)
19	CONTINUE
C
C	PLOT SIDE PLATE
C
71	CALL PLOT(H(NX,1),H(NX,2),3)
	DO 23 I=1,NZ				!PLOT RIGHT SIDE CURVE
		IF (NX+I.GT.MAXSIZE) GOTO 999
		CALL VXPT3D(XP,YP,A(NX,I),NX,I,NX)
		H(NX+I,1)=XP
		H(NX+I,2)=YP
		CALL PLOT(XP,YP,2)
23	CONTINUE
	CALL VXPT3D(XP,YP,AMIN,NX,1,NX)
	CALL PLOT(XP,YP,3)
	IHOLD=NX+NZ				!NUMBER OF H VALUES
	IF (JFF.EQ.1) GOTO 5			!DON'T PLOT SIDE PLATES
	DO 24 I=2,NZ				!ADD SIDE LINES
		CALL VXPT3D(XP2,YP2,AMIN,NX,I,NX)
		CALL PLOT(XP2,YP2,2)
		CALL VXPT3D(XP,YP,A(NX,I),NX,I,NX)
		CALL PLOT(XP,YP,2)
		CALL PLOT(XP,YP2,3)
24	CONTINUE
C
C	BEGIN MAIN LOOP
C
   5	DO 500 IZ=2,NZ				!OVER Z DIMENSION TOWARD REAR
		IPCT=1
		IDCT=1
		IHCT=1
C
C	DETERMINE START POINT LOCATION
C
		CALL VXPT3D(XP1,YP1,A(IDCT,IZ),1,IZ,NX)	!LEFT MOST DATA POINT
C
		IF (XP1.LT.H(1,1)) THEN 	!DATA TO LEFT OF HISTORY ARRAY
C			IF (IPCT.GT.MAXSIZE) GOTO 999
C			P(IPCT,1)=XP1
C			P(IPCT,2)=YP1
C			IPCT=IPCT+1
			CALL PLOT(XP1,YP1,3)
			DO 6 I=1,NX		!(VERY RARE)
				CALL VXPT3D(XP1,YP1,A(I,IZ),I,IZ,NX)
				IF (XP1.GT.H(1,1)) THEN
					IDCT=I-1
					CALL VXPT3D(DX1,DY1,A(IDCT,IZ),
     $						IDCT,IZ,NX)
					HHIGH=.FALSE.
					HX1=H(1,1)
					HY1=H(1,2)
					HX2=H(2,1)
					HY2=H(2,2)
					IDCT=IDCT+1
					IHCT=IHCT+2
					CALL VXPT3D(DX2,DY2,A(IDCT,IZ),
     $						IDCT,IZ,NX)
					IDCT=IDCT+1
					GOTO 100
				ENDIF
				IF (IPCT.GT.MAXSIZE) GOTO 999
				P(IPCT,1)=XP1
				P(IPCT,2)=YP1
				IPCT=IPCT+1
				CALL PLOT(XP1,YP1,2)
6			CONTINUE
		ENDIF
C
		IDCT=2
		CALL VXPT3D(DX1,DY1,A(1,IZ-1),1,IZ-1,NX)
		CALL VXPT3D(DX2,DY2,A(1,IZ),1,IZ,NX)
CC		CALL PLOT(H(1,1),H(1,2),3)
		X0=H(1,1)
		Y0=H(1,2)
		IP=3
		IF (IPCT.GT.MAXSIZE) GOTO 999
		P(IPCT,1)=H(1,1)
		P(IPCT,2)=H(1,2)
		IPCT=IPCT+1
		DO 7 I=2,IHOLD
			IF (H(I,1).GT.DX1) GOTO 8
				IF (IPCT.GT.MAXSIZE) GOTO 999
				P(IPCT,1)=H(I,1)
				P(IPCT,2)=H(I,2)
				IPCT=IPCT+1
CC				CALL PLOT(H(I,1),H(I,2),2)
				X0=H(I,1)
				Y0=H(I,2)
7		CONTINUE
8		IHCT=I-1
		HX1=H(IHCT,1)
		HY1=H(IHCT,2)
		HX2=H(IHCT+1,1)
		HY2=H(IHCT+1,2)
		IHCT=IHCT+2
		HHIGH=.TRUE.
		IF (HX1.EQ.HX2) THEN
			IF (IHCT.EQ.IHOLD) GOTO 100
			IHCT=IHCT+1
			GOTO 8
		ENDIF
		AMH=(HY2-HY1)/(HX2-HX1)
		BH=HY1-HX1*AMH
		YP=AMH*DX1+BH
		IF (YP.LE.DY1) HHIGH=.FALSE.
		IF (HY1.EQ.DY1.AND.HX1.EQ.DX1) THEN
			HHIGH=.TRUE.
			YP=AMH*DX2+BH
			IF (YP.LT.DY2) HHIGH=.FALSE.
		ENDIF
C
C	TOP OF INNER LOOP
C
100		CONTINUE
			CALL INTERSECT(FLAG,X,Y,HX1,HY1,HX2,HY2,DX1,DY1
     $				,DX2,DY2,HHIGH)
			IF (FLAG) THEN		!SEGMENTS INTERSECT
				HX1=X		!DRAW SEGMENT WITH
				HY1=Y		!HIGHEST START POINT
				DX1=X		!TO THE INTERSECTION
				DY1=Y
				IF (IPCT.GT.MAXSIZE) GOTO 999
				P(IPCT,1)=X
				P(IPCT,2)=Y
				IPCT=IPCT+1
				IF (IP.EQ.2) CALL PLOT(X,Y,2)
				X0=X
				Y0=Y
				GOTO 100
			ENDIF
C
			IF (HX2.LE.DX2) THEN	!CHECKED ALL H SEGS OVER D SEGS
				IF (HHIGH) THEN !DRAW HIGHEST SEGMENT
					IF (IPCT.GT.MAXSIZE) GOTO 999
					P(IPCT,1)=HX2
					P(IPCT,2)=HY2
					IPCT=IPCT+1
					IF (IP.EQ.3) CALL PLOT(X0,Y0,3)
					CALL PLOT(HX2,HY2,2)
					X0=HX2
					Y0=HY2
					IP=2
				ENDIF
				HX1=HX2
				HY1=HY2
				HX2=H(IHCT,1)
				HY2=H(IHCT,2)
				IHCT=IHCT+1
				IF (IHCT.GT.IHOLD+1) THEN
 34					CONTINUE
					IF (IDCT.LE.NX+1) THEN
						CALL VXPT3D(X,Y,A(IDCT-1,
     $						  IZ),IDCT-1,IZ,NX)
						IF(IPCT.GT.MAXSIZE)GOTO 999
						P(IPCT,1)=X
						P(IPCT,2)=Y
						IPCT=IPCT+1
					IF (IP.EQ.3) CALL PLOT(X0,Y0,3)
						IP=2
						CALL PLOT(X,Y,2)
						IDCT=IDCT+1
						GOTO 34
					ENDIF
					GOTO 200	!DONE WITH H'S
				ENDIF
				IF (HX1.EQ.DX2) THEN
					DX1=DX2 	!NEXT DATA POINT
					DY1=DY2
					X0=DX1
					Y0=DY1
CC					IF (.NOT.HHIGH)CALL PLOT(DX1,DY1,2)
					CALL VXPT3D(DX2,DY2,A(IDCT,IZ),
     $						IDCT,IZ,NX)
					IDCT=IDCT+1
					IF (IDCT.GT.NX+2) GOTO 235!DONE WITH DATA
					IF (IDCT.GT.NX+1) THEN
						DX2=DX1
						DY2=AMIN
					ENDIF
					HHIGH=.TRUE.
					IF (DY1.GT.HY1) HHIGH=.FALSE.
				ENDIF
				GOTO 100
			ELSE
				IF (.NOT.HHIGH) THEN	!PLOT DATA THAT IS HIGHEST
					IF (IPCT.GT.MAXSIZE) GOTO 999
					P(IPCT,1)=DX2
					P(IPCT,2)=DY2
					IPCT=IPCT+1
					IF (IP.EQ.3) CALL PLOT(X0,Y0,3)
					CALL PLOT(DX2,DY2,2)
					IP=2
					X0=DX2
					Y0=DY2
				ENDIF
				DX1=DX2 	!NEXT DATA POINT
				DY1=DY2
				CALL VXPT3D(DX2,DY2,A(IDCT,IZ),IDCT,IZ,NX)
				IDCT=IDCT+1
				IF (IDCT.GT.NX+2) GOTO 235!DONE WITH DATA
				IF (IDCT.GT.NX+1) THEN
					DX2=DX1
					DY2=AMIN
				ENDIF
			ENDIF
C
C	DONE WITH INNER LOOP
C
			GOTO 100
C
200		IHOLD=IPCT-1			!STORE NEW HISTORY
		DO 201 I=1,IPCT
			H(I,1)=P(I,1)
			H(I,2)=P(I,2)
201		CONTINUE
C
C	END MAIN LOOP
C
500	CONTINUE
C
520	CALL PLOT(0.,0.,3)			!PEN UP
	IF (IFLAG.GT.0) THEN
		CALL CTERM(2)			!CLEAR TERMINAL
		CALL PLOTND			!CLOSE PLOT OUTPUT
		REPEAT=.FALSE.
	ENDIF
	IF (IFLAG.LT.0) THEN
		REPEAT=.TRUE.
		CALL CTERM(1)			!PUT TERMINAL IN TEXT MODE
	ENDIF
	RETURN
235	CONTINUE				!FINISH H CURVE WHEN OUT OF DATA
	IHCT=IHCT-1
236	CONTINUE
	IF (IHCT.GT.IHOLD) GOTO 200
		X=H(IHCT,1)
		Y=H(IHCT,2)
		IHCT=IHCT+1
		IF (IPCT.GT.MAXSIZE) GOTO 999
		P(IPCT,1)=X
		P(IPCT,2)=Y
		IPCT=IPCT+1
CC		CALL PLOT(X,Y,2)
		IDCT=IDCT+1
	GOTO 236
999	CALL CTERM(1)
	WRITE(*,3002)
3002	FORMAT(' *** VAX3DX INTERNAL MEMORY OVERFLOW ERROR ***')
	GOTO 520
	END
C
	SUBROUTINE VXPT3D(X,Y,AVAL,IX,IZ,NX)
C
C	CREATED BY DAVID LONG    AUG, 1982	AT JPL
C	SUBPROGRAM OF VAX3D
C
C	ROUTINE TO DETERMINE X,Y VALUE OF A POINT ON 3-D SURFACE
C	FOR VAX3DX
C
	COMMON /LOCATE/ XSCALE,YSCALE,ZSCALE,AMIN,ALPH,BET
	X=XSCALE*FLOAT(IX-1)*COS(ALPH)+FLOAT(IZ-1)*COS(BET)*ZSCALE
	Y=YSCALE*(AVAL-AMIN)+FLOAT(NX-IX+1)*SIN(ALPH)*XSCALE+
     $		FLOAT(IZ-1)*SIN(BET)*ZSCALE
	RETURN
	END
C
C
	SUBROUTINE INTERSECT(FLAG,X,Y,AX1,AY1,AX2,AY2,BX1,BY1,BX2,BY2,A)
C
C	CREATED BY D. LONG     AUG, 1983	AT JPL
C	SUBPROGRAM OF VAX3DX
C
C	DETERMINE IF TWO SEGMENTS INTERSECT AND THE POINT OF INTERSECTION
C	IF STARTING POINTS OF SEGMENTS ARE THE SAME SEGMENTS ARE NOT
C	CONSIDERED TO BE INTERSECTING
C
	REAL MA,MB
	LOGICAL FLAG,VERT,A
C
	VERT=.FALSE.
	FLAG=.FALSE.
C
	IF (AX1.EQ.BX1.AND.AY1.EQ.BY1) RETURN	!SAME START POINT
	IF (AX2.EQ.BX2.AND.AY2.EQ.BY2) THEN	!SAME END POINT
		FLAG=.TRUE.
		X=AX2
		Y=AY2
		RETURN
	ENDIF
C
	DENOM=AX1-AX2
	IF (DENOM.EQ.0.0) THEN		!VERTICAL LINE
		MA=1.E10
		VERT=.TRUE.
	ELSE
		MA=(AY1-AY2)/DENOM	!SLOPE OF SEGMENT A
	ENDIF
	DENOM=BX1-BX2
	IF (DENOM.EQ.0.0) THEN		!VERTICAL LINE
		MB=1.E10
		VERT=.TRUE.
	ELSE
		MB=(BY1-BY2)/DENOM	!SLOPE OF SEGMENT B
	ENDIF
	IF (MA.EQ.MB) RETURN		!PARALELL
	CA=AY1-MA*AX1
	CB=BY1-MB*BX1
	IF (VERT) THEN
		IF (MA.EQ.1.E10) THEN
			X=AX1
			Y=X*MB+CB
		ENDIF
		IF (MB.EQ.1.E10) THEN
			X=BX1
			Y=X*MA+CA
		ENDIF
	ELSE
		X=(CA-CB)/(MB-MA)
		Y=MA*X+CA
	ENDIF
C	INTERSECTION OF LINES THROUGH POINTS IS AT X,Y
	DA=(AX1-AX2)**2+(AY1-AY2)**2
	DA1=(AX1-X)**2+(AY1-Y)**2
	IF (DA1.GT.DA) RETURN
		DA2=(AX2-X)**2+(AY2-Y)**2
		IF (DA2.GT.DA) RETURN
			DB=(BX1-BX2)**2+(BY1-BY2)**2
			DB1=(BX1-X)**2+(BY1-Y)**2
			IF (DB1.GT.DB) RETURN
				DB2=(BX2-X)**2+(BY2-Y)**2
				IF (DB2.GT.DB) RETURN
					IF (MA.GT.MB) THEN
						A=.TRUE.
					ELSE
						A=.FALSE.
					ENDIF
					FLAG=.TRUE.
					RETURN
	END
C
C *************************************************************************
C
	SUBROUTINE PLOTLG2(X,Y,NN,NP,IFLAG,NSYM,XAXL,YAXL,XTITL,NXT,
     1		YTITL,NYT,TITLE,NT,XMIN,XMAX,YMIN,YMAX,ICOL,ILINE)
C
C	CREATED BY D. LONG       OCT, 1983	AT JPL
C	REVISED BY D. LONG     FEB, 1986 -- ADDED LINE TYPE ARRAY
C
C	ROUTINE TO PLOT SEVERAL LINES OF DATA IN LOG/LINEAR COMBINATION
C
C	X	REAL X VALUE ARRAY
C	Y	REAL Y DATA ARRAY DIMENSION Y(NP,NN)
C	NN	INT  # NUMBER OF ARRAYS
C	NP	INT  # OF POINTS IN ARRAY
C	IFLAG	INT
C	  (MAG) >10000 REPEAT PLOTTING BUT DO NOT INTIALIZE PLOTTER
C		< 0  REPEAT PLOTTING (DON'T CLOSE PLOTTER OUTPUT)
C		= 0  CLOSE PLOTTER OUTPUT--DO NOT PRODUCE PLOT
C		> 0  SINGLE PLOT OUTPUT ONLY (PLOTTER OUTPUT CLOSED)
C	  (ONE'S DIGIT) = 1 X LINEAR, Y LOGRITHMIC (BASE 10)
C	  (ONE'S DIGIT) = 2 X LOGRITHMIC,Y LINEAR
C	  (ONE'S DIGIT) = 3 X LOGRITHMIC,Y LOGRITHMIC
C	  (ONE'S DIGIT) = 4 X LINEAR, Y LINEAR
C	  (TEN'S DIGIT) = 0 NO AXIS OR GRID 
C	  (TEN'S DIGIT) = 1 PLOT BOX WITH AXIS TICKS
C	  (TEN'S DIGIT) = 2 PLOT SOLID GRID
C	  (TEN'S DIGIT) = 3 PLOT TICKED GRID W/O BOX
C	  (TEN'S DIGIT) = 4 PLOT TICKED GRID WITH BOX
C	  (TEN'S DIGIT) = 5 PLOT BOX WITH AXIS TICKS AND TICKED GRID
C	  (TEN'S DIGIT) = 6 PLOT W/O BOX OR GRID BUT USE AXISES
C	  (TEN'S DIGIT) = 7 PLOT SOLID LOGRITHMIC GRID
C	  (TEN'S DIGIT) = 8 PLOT DOTTED LOGRITHMIC GRID
C	  (TEN'S DIGIT) = 9 PLOT TICKED LOGRITHMIC GRID
C     (HUNDRED'S DIGIT) = 0 ASK WHICH SCREEN DEVICE TO USE
C		      <>0 SCREEN DEVICE CODE NUMBER
C	NSYM	INT   NUMBER OF POINTS BETWEEN SYMBOLS
C		      < 0  SYMBOLS ONLY, NO LINE
C		      = 0  NO SYMBOLS, LINE ONLY
C		      > 0 NUMBER OF POINTS BETWEEN SYMBOLS
C	XAXL	REAL  X AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C	YAXL	REAL  Y AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C
C NOTE: 	XMIN,XMAX,YMIN,YMAX ARE ONLY REQUIRED IF XAXL OR YAXL < 0
C
C	XTITL	CHAR  X AXIS TITLE
C	NXT	INT   NUMBER OF CHARACTERS IN X AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	YTITL	CHAR  Y AXIS TITLE
C	NYT	INT   NUMBER OF CHARACTERS IN Y AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	TITLE	CHAR  PLOT TITLE
C	NT	INT   NUMBER OF CHARACTERS IN PLOT TITLE
C		= 0  NO TITLE
C		< 0  USE PEN COLOR ARRAY
C			IF IABS(NT)/100)>1 USE LINE TYPE ARRAY
C		      (REQUIRES XMIN,XMAX,YMIN,YMAX BE PRESENT)
C	XMIN	REAL  MINIMUM VALUE DISPLAYED ON X AXIS
C	XMAX	REAL  MAXIMUM VALUE DISPLAYED ON X AXIS
C	YMIN	REAL  MINIMUM VALUE OF Y ARRAY
C	YMAX	REAL  MAXIMUM VALUE OF Y ARRAY
C	ICOL	INT   ARRAY OF PEN COLORS DIMENSIONED ICOL(5+NN)
C			ICOL(1) = GRID COLOR
C			ICOL(2) = AXIS LINE COLOR
C			ICOL(3) = AXIS NUMBERS COLOR
C			ICOL(4) = AXIS TITLE COLOR
C			ICOL(5) = AXIS EXPONENT COLOR
C			ICOL(6) = TITLE COLOR (COLOR UPON RETURN)
C			ICOL(7) = LINE COLOR 1
C			ICOL(8) = LINE COLOR 2
C			   .	     .	     3
C	ILINE	INT  LINE TYPE ARRAY FOR LINES DIMENSIONED ILINE(NN)
C
	INTEGER XTITL(1),YTITL(1),TITLE(1)
	REAL Y(NP,NN),X(NP),PY(2)
	LOGICAL REPEAT
	INTEGER PL,ICOL(1),IC(4),ILINE(1)
	COMMON /CPLOTLG2/XM,DX,YM,DY
	DATA REPEAT/.FALSE./
	PL=3					!PRINTER DATA FILE= FOR003.DAT
	IF (IFLAG.EQ.0) THEN
		IF (REPEAT) CALL PLOTND !CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
		RETURN
	ENDIF
	JF=IABS(IFLAG)
	IF (.NOT.REPEAT.AND.JF.LT.10000) THEN
		ILU=-(JF/100)			!SCREEN DEVICE, CLEAR SCREEN
		CALL FRAME(PL,ILU,1.2,1.2,1.)	!INTIALIZE PLOT PACKAGE
	ELSE
		CALL CTERM(-1)			!RESTORE PLOT MODE
C		CALL NEWPAGE			!NEW PAGE
		JF=MOD(JF,100)
	ENDIF
	JF=MOD(JF,100)
	IF=JF
	IF (IF.GT.10) IF=MOD(IF,10)
	JF=JF-IF
	NX=ABS(ANINT(XAXL))				!GRID SIZES
	NY=ABS(ANINT(YAXL))
	IF (XAXL.GT.0.0) THEN				!INPUT SCALING
	    XM=X(1)
	    DX=X(1)
	    DO 5 I=2,NP
		XM=MAX(X(I),XM)
		DX=MIN(X(I),DX)
 5	    CONTINUE
	    PY(1)=XM
	    PY(2)=DX
	    IF (IF.EQ.2.OR.IF.EQ.3) THEN
		CALL SCALG(PY,ABS(XAXL),2,1,1,XM,DX)	!SMOOTH SCALE FACTORS
		IK=-1
		GDX=1./DX
		NX=DX*ABS(XAXL)
		INX=-1
	    ELSE
		CALL SCALE(PY,ABS(XAXL),2,1,1,XM,DX)	!SMOOTH SCALE FACTORS
		IK=0
		GDX=1.
		INX=1
	    ENDIF
	ELSE
	    IF (IF.EQ.2.OR.IF.EQ.3) THEN
		XM=(ABS(XMIN)+1.E-25)
		IF (XM.NE.AINT(XM)) XM=AINT(XM)-1.
		DX=AINT(ALOG10(ABS(XMAX)+1.E-25))+1.
		DX=(DX-XM)/ABS(XAXL)
		GDX=1./DX
		IK=-1
		NX=DX*ABS(XAXL)
		INX=-1
	    ELSE
		XM=XMIN
		DX=(XMAX-XMIN)/ABS(XAXL)
		GDX=1.
		IK=0
		INX=1
	    ENDIF
	ENDIF
	IF (YAXL.GT.0.0) THEN				!INPUT SCALING
	    YM=Y(1,1)
	    DY=Y(1,1)
	    DO 6 IN=1,NN
		DO 6 I=1,NP
		    YM=MAX(Y(I,IN),YM)
		    DY=MIN(Y(I,IN),DY)
6		CONTINUE
	    PY(1)=YM
	    PY(2)=DY
	    IF (IF.EQ.1.OR.IF.EQ.3) THEN
		CALL SCALG(PY,ABS(YAXL),2,1,1,YM,DY)	!SMOOTH SCALE FACTORS
		IK=-1+IK
		GDY=1./DY
		NY=DY*ABS(YAXL)
		INY=-1
	    ELSE
		CALL SCALE(PY,ABS(YAXL),2,1,1,YM,DY)	!SMOOTH SCALE FACTORS
		IK=1+IK
		GDY=1.
		INY=1
	    ENDIF
	ELSE
	    IF (IF.EQ.1.OR.IF.EQ.3) THEN
		YM=ALOG10(ABS(YMIN)+1.E-25)
		IF (YM.NE.AINT(YM)) YM=AINT(YM)-1.
		DY=AINT(ALOG10(ABS(YMAX)+1.E-25))+1.
		DY=(DY-YM)/ABS(YAXL)
		GDY=1./DY
		NY=DY*ABS(YAXL)
		IK=-1+IK
		INY=-1
	    ELSE
		YM=YMIN
		DY=(YMAX-YMIN)/ABS(YAXL)
		IK=1+IK
		GDY=1.
		INY=1
	    ENDIF
	ENDIF
	IF (JF.EQ.0) GOTO 77		!NO AXIS OR GRID
	IF (JF.EQ.60) GOTO 76		!NO GRID
	IF (JF.GT.60) THEN		!LOGRITHMIC GRID
		II=0
		IF (JF.EQ.70) II=1
		IF (JF.EQ.80) II=2
		CALL LGRID(0.,0.,GDX,GDY,INX*NX,INY*NY,II)
		GOTO 76
	ENDIF
	IF (JF.GE.20) THEN		!CARTESIAN GRID
		IF (JF.GE.30) NX=-NX
		IF (JF.GE.40) NY=-NY
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(1)),0.,0) !PEN COLOR
		CALL GRID(0.,0.,GDX,GDY,NX,NY)		!PRODUCE GRID
		IF (JF.EQ.50) JF=10
	ENDIF
76	NADD=0
	IF (NT.LT.0) THEN
		NADD=100000		!PEN COLOR
		IC(1)=ICOL(2)
		IC(2)=ICOL(3)
		IC(3)=ICOL(4)
		IC(4)=ICOL(5)
	ENDIF
	IX=IABS(NXT)
	XL=ABS(XAXL)*SIGN(1.,FLOAT(NXT))		!AXIS LENGTH WITH TICK INFOR
	IF (NXT.NE.0) THEN
		IF (IF.EQ.2.OR.IF.EQ.3) THEN
		CALL LGAXS(0.,0.,XTITL,-IX-NADD,XL,0.,XM,DX,IC) !X-AXIS
		IF (JF.EQ.10) CALL LGAXS(0.,ABS(YAXL),XTITL,IX+100+NADD,
     $			XL,0.,XM,DX,IC) !X-AXIS
		ELSE
		CALL AXIS(0.,0.,XTITL,-IX-NADD,XL,0.,XM,DX,N1,N2,IC)  !X-AXIS
		IF (JF.EQ.10) CALL AXIS(0.,ABS(YAXL),XTITL,IX+100+NADD,
     $			XL,0.,XM,DX,N1,N2,IC)  !X-AXIS
		ENDIF
	ENDIF
	IY=IABS(NYT)+1000
	YL=ABS(YAXL)*SIGN(1.,FLOAT(NYT))
	IF (NYT.NE.0) THEN
		IF (IF.EQ.1.OR.IF.EQ.3) THEN
		CALL LGAXS(0.,0.,YTITL,IY+NADD,YL,90.,YM,DY,IC) !Y-AXIS
		IF (JF.EQ.10) CALL LGAXS(ABS(XAXL),0.,YTITL,-IY-100-NADD,
     $			YL,90.,YM,DY,IC) !Y-AXIS
		ELSE
		CALL AXIS(0.,0.,YTITL,IY+NADD,YL,90.,YM,DY,N1,N2,IC)  !Y-AXIS
		IF (JF.EQ.10) CALL AXIS(ABS(XAXL),0.,YTITL,-IY-100-NADD,
     $			YL,90.,YM,DY,N1,N2,IC)	!Y-AXIS
		ENDIF
	ENDIF
77	IF (IK.EQ.1) THEN
	    DO 78 IN=1,NN
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6+IN)),0.,0)  !PEN COLOR
		IF (IABS(NT)/100.GT.0) CALL NEWPEN(ILINE(IN))	!LINE TYPE
		CALL LINE(X,Y(1,IN),NP,1,NSYM,IN-1,1,1,XM,DX,YM,DY) !PLOT DATA
78	    CONTINUE
	ELSE
	    IF (IK.EQ.-1) IK=1				    !CORRECT FLAG
	    IF (IK.EQ.0) IK=-1
	    DO 79 IN=1,NN
	    IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6+IN)),0.,0)!PEN COLOR
	    IF (IABS(NT)/100.GT.0) CALL NEWPEN(ILINE(IN)) !LINE TYPE
	    CALL LGLIN(X,Y(1,IN),NP,1,NSYM,IN-1,IK,1,1,XM,DX,YM,DY)!PLOT DATA
79	    CONTINUE
	ENDIF
	IF (IABS(NT)/100.GT.0) CALL NEWPEN(0)		!RESET LINE TYPE
	CS=.21						!TITLE CHARACTER SIZE
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6)),0.,0)	!PEN COLOR
	IF (NT.NE.0.AND.JF.NE.0) THEN			!PLOT TITLE
		XP=0.0
		YP=0.0
		CALL SYMBOL(XP,YP,CS,TITLE,
     $			0.,MOD(IABS(NT),100),-3)	!TITLE LENGTH
		XP=ABS(XAXL/2.)-XP/2.
		IF (XP.LT.0.) XP=0.
		CALL SYMBOL(XP,ABS(YAXL)+.15,CS,TITLE,
     $			0.,MOD(IABS(NT),100),-1)	!PLOT TITLE
	ENDIF
	CALL PLOT(0.,0.,3)
	IF (IFLAG.GT.0) THEN
		CALL CTERM(2)				!ASK IF CLEAR SCREN
		CALL PLOTND				!CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
	ENDIF
	IF (IFLAG.LT.0) THEN
		REPEAT=.TRUE.
		CALL CTERM(1)				!RETURN TO TEXT MODE
	ENDIF
	RETURN
	END
C
C *************************************************************************
C
	SUBROUTINE SCATPL(X,Y,NN,NP,IFLAG,NSYM,SIZE,XAXL,YAXL,XTITL,NXT,
     1			YTITL,NYT,TITLE,NT,XMIN,XMAX,YMIN,YMAX,ICOL)
C
C	CREATED BY D. LONG       NOV, 1983	AT JPL
C
C	ROUTINE TO PLOT A SCATTER PLOT WITH SEVERAL DIFFERENT PATTERNS
C
C	X	REAL X DATA ARRAY DIMENSION X(NP,NN)
C	Y	REAL Y DATA ARRAY DIMENSION Y(NP,NN)
C	NN	INT  # NUMBER OF ARRAYS (IF NN=1 A 1D ARRAY MAY BE USED)
C	NP	INT  # OF POINTS IN ARRAY
C	IFLAG	INT
C	  (MAG) >10000 REPEAT PLOTTING BUT DO NOT INTIALIZE PLOTTER
C		< 0  REPEAT PLOTTING (DON'T CLOSE PLOTTER OUTPUT)
C		= 0  CLOSE PLOTTER OUTPUT--DO NOT PRODUCE PLOT
C		> 0  SINGLE PLOT OUTPUT ONLY (PLOTTER OUTPUT CLOSED)
C	  (ONE'S DIGIT) = 1 X LINEAR, Y LOGRITHMIC (BASE 10)
C	  (ONE'S DIGIT) = 2 X LOGRITHMIC,Y LINEAR
C	  (ONE'S DIGIT) = 3 X LOGRITHMIC,Y LOGRITHMIC
C	  (ONE'S DIGIT) = 4 X LINEAR, Y LINEAR
C	  (TEN'S DIGIT) = 0 NO AXIS OR GRID 
C	  (TEN'S DIGIT) = 1 PLOT BOX WITH AXIS TICKS
C	  (TEN'S DIGIT) = 2 PLOT SOLID GRID
C	  (TEN'S DIGIT) = 3 PLOT TICKED GRID W/O BOX
C	  (TEN'S DIGIT) = 4 PLOT TICKED GRID WITH BOX
C	  (TEN'S DIGIT) = 5 PLOT BOX WITH AXIS TICKS AND TICKED GRID
C	  (TEN'S DIGIT) = 6 PLOT W/O BOX OR GRID BUT USE AXISES
C	  (TEN'S DIGIT) = 7 PLOT SOLID LOGRITHMIC GRID
C	  (TEN'S DIGIT) = 8 PLOT DOTTED LOGRITHMIC GRID
C	  (TEN'S DIGIT) = 9 PLOT TICKED LOGRITHMIC GRID
C     (HUNDRED'S DIGIT) = 0 ASK WHICH SCREEN DEVICE TO USE
C		      <>0 SCREEN DEVICE CODE NUMBER
C	NSYM	INT   SYMBOL ARRAY DIMENSIONED NSYM(NN)
C		      NSYM(I) <  0  NO SYMBOLS, POINT ONLY
C		      NSYM(I) >= 0  SYMBOL NUMBER
C	SIZE    REAL  SIZE OF PLOTTED SYMBOL (IF ZERO 0.1 IS USED)
C	XAXL	REAL  X AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C	YAXL	REAL  Y AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C
C NOTE: 	XMIN,XMAX,YMIN,YMAX ARE ONLY REQUIRED IF XAXL OR YAXL < 0
C
C	XTITL	CHAR  X AXIS TITLE
C	NXT	INT   NUMBER OF CHARACTERS IN X AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	YTITL	CHAR  Y AXIS TITLE
C	NYT	INT   NUMBER OF CHARACTERS IN Y AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	TITLE	CHAR  PLOT TITLE
C	NT	INT   NUMBER OF CHARACTERS IN PLOT TITLE
C		= 0  NO TITLE
C		< 0  USE COLOR ARRAY (REQUIRES XMIN,XMAX,YMIN,YMAX TOO)
C	XMIN	REAL  MINIMUM VALUE DISPLAYED ON X AXIS
C	XMAX	REAL  MAXIMUM VALUE DISPLAYED ON X AXIS
C	YMIN	REAL  MINIMUM VALUE OF Y ARRAY
C	YMAX	REAL  MAXIMUM VALUE OF Y ARRAY
C
C	ICOL	INT   ARRAY OF PEN COLORS DIMENSIONED ICOL(NP+6)
C			ICOL(1) = GRID COLOR
C			ICOL(2) = AXIS LINE COLOR
C			ICOL(3) = AXIS NUMBERS COLOR
C			ICOL(4) = AXIS TITLE COLOR
C			ICOL(5) = AXIS EXPONENT COLOR
C			ICOL(6) = TITLE COLOR (COLOR UPON RETURN)
C			ICOL(7) = POINT SET COLOR 1
C			ICOL(8) = POINT SET COLOR 2
C			   .	     .	          3
C
	INTEGER XTITL(1),YTITL(1),TITLE(1)
	REAL Y(NP,NN),X(NP,NN),PY(2)
	LOGICAL REPEAT
	INTEGER PL,ICOL(1),IC(4),NSYM(1)
	COMMON /CSCATPL/XM,DX,YM,DY
	DATA REPEAT/.FALSE./
	PL=3						!PRINTER DATA FILE= FOR003.DAT
	IF (IFLAG.EQ.0) THEN
		IF (REPEAT) CALL PLOTND !CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
		RETURN
	ENDIF
	JF=IABS(IFLAG)
	IF (.NOT.REPEAT.AND.JF.LT.1000) THEN
		ILU=-(JF/100)				!SCREEN DEVICE, CLEAR SCREEN
		CALL FRAME(PL,ILU,1.2,1.2,1.)		!INTIALIZE PLOT PACKAGE
	ELSE
		CALL CTERM(-1)				!RESTORE PLOT MODE
C		CALL NEWPAGE				!NEW PAGE
		JF=MOD(JF,100)
	ENDIF
	JF=MOD(JF,100)
	IF=JF
	IF (IF.GT.10) IF=MOD(IF,10)
	JF=JF-IF
	NX=ABS(ANINT(XAXL))				!GRID SIZES
	NY=ABS(ANINT(YAXL))
	IF (XAXL.GT.0.0) THEN				!INPUT SCALING
	    XM=X(1,1)
	    DX=X(1,1)
	    DO 4 N=1,NN
	    DO 4 I=2,NP
		XM=MAX(X(I,N),XM)
		DX=MIN(X(I,N),DX)
   4	    CONTINUE
	    PY(1)=XM
	    PY(2)=DX
	    IF (IF.EQ.2.OR.IF.EQ.3) THEN
		CALL SCALG(PY,ABS(XAXL),2,1,1,XM,DX)	!SMOOTH SCALE FACTORS
		IK=-1
		GDX=1./DX
		NX=DX*ABS(XAXL)
		INX=-1
	    ELSE
		CALL SCALE(PY,ABS(XAXL),2,1,1,XM,DX)	!SMOOTH SCALE FACTORS
		IK=0
		GDX=1.
		INX=1
	    ENDIF
	ELSE
	    IF (IF.EQ.2.OR.IF.EQ.3) THEN
		XM=(ABS(XMIN)+1.E-25)
		IF (XM.NE.AINT(XM)) XM=AINT(XM)-1.
		DX=AINT(ALOG10(ABS(XMAX)+1.E-25))+1.
		DX=(DX-XM)/ABS(XAXL)
		GDX=1./DX
		IK=-1
		NX=DX*ABS(XAXL)
		INX=-1
	    ELSE
		XM=XMIN
		DX=(XMAX-XMIN)/ABS(XAXL)
		GDX=1.
		IK=0
		INX=1
	    ENDIF
	ENDIF
	IF (YAXL.GT.0.0) THEN				!INPUT SCALING
	    YM=Y(1,1)
	    DY=Y(1,1)
	    DO 5 N=1,NN
		DO 5 I=1,NP
		    YM=MAX(Y(I,N),YM)
		    DY=MIN(Y(I,N),DY)
5	    CONTINUE
	    PY(1)=YM
	    PY(2)=DY
	    IF (IF.EQ.1.OR.IF.EQ.3) THEN
		CALL SCALG(PY,ABS(YAXL),2,1,1,YM,DY)	!SMOOTH SCALE FACTORS
		IK=-1+IK
		GDY=1./DY
		NY=DY*ABS(YAXL)
		INY=-1
	    ELSE
		CALL SCALE(PY,ABS(YAXL),2,1,1,YM,DY)	!SMOOTH SCALE FACTORS
		IK=1+IK
		GDY=1.
		INY=1
	    ENDIF
	ELSE
	    IF (IF.EQ.1.OR.IF.EQ.3) THEN
		YM=ALOG10(ABS(YMIN)+1.E-25)
		IF (YM.NE.AINT(YM)) YM=AINT(YM)-1.
		DY=AINT(ALOG10(ABS(YMAX)+1.E-25))+1.
		DY=(DY-YM)/ABS(YAXL)
		GDY=1./DY
		NY=DY*ABS(YAXL)
		IK=-1+IK
		INY=-1
	    ELSE
		YM=YMIN
		DY=(YMAX-YMIN)/ABS(YAXL)
		IK=1+IK
		GDY=1.
		INY=1
	    ENDIF
	ENDIF
	IF (JF.EQ.0) GOTO 77				!NO AXIS OR GRID
	IF (JF.EQ.60) GOTO 76				!NO GRID
	IF (JF.GT.60) THEN				!LOGRITHMIC GRID
		II=0
		IF (JF.EQ.70) II=1
		IF (JF.EQ.80) II=2
		CALL LGRID(0.,0.,GDX,GDY,INX*NX,INY*NY,II)
		GOTO 76
	ENDIF
	IF (JF.GE.20) THEN				!CARTESIAN GRID
		IF (JF.GE.30) NX=-NX
		IF (JF.GE.40) NY=-NY
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(1)),0.,0) ! PEN COLOR
		CALL GRID(0.,0.,GDX,GDY,NX,NY)		!PRODUCE GRID
		IF (JF.EQ.50) JF=10
	ENDIF
76	NADD=0
	IF (NT.LT.0) THEN
		NADD=100000				!PEN COLOR
		IC(1)=ICOL(2)
		IC(2)=ICOL(3)
		IC(3)=ICOL(4)
		IC(4)=ICOL(5)
	ENDIF
	IX=IABS(NXT)
	XL=ABS(XAXL)*SIGN(1.,FLOAT(NXT))		!AXIS LENGTH WITH TICK INFOR
	IF (NXT.NE.0) THEN
		IF (IF.EQ.2.OR.IF.EQ.3) THEN
		CALL LGAXS(0.,0.,XTITL,-IX-NADD,XL,0.,XM,DX,IC) !X-AXIS
		IF (JF.EQ.10) CALL LGAXS(0.,ABS(YAXL),XTITL,IX+100+NADD,
     $			XL,0.,XM,DX,IC) 		!X-AXIS
		ELSE
		CALL AXIS(0.,0.,XTITL,-IX-NADD,XL,0.,XM,DX,N1,N2,IC)  !X-AXIS
		IF (JF.EQ.10) CALL AXIS(0.,ABS(YAXL),XTITL,IX+100+NADD,
     $			XL,0.,XM,DX,N1,N2,IC)  		!X-AXIS
		ENDIF
	ENDIF
	IY=IABS(NYT)+1000
	YL=ABS(YAXL)*SIGN(1.,FLOAT(NYT))
	IF (NYT.NE.0) THEN
		IF (IF.EQ.1.OR.IF.EQ.3) THEN
		CALL LGAXS(0.,0.,YTITL,IY+NADD,YL,90.,YM,DY,IC) !Y-AXIS
		IF (JF.EQ.10) CALL LGAXS(ABS(XAXL),0.,YTITL,-IY-100-NADD,
     $			YL,90.,YM,DY,IC) 		!Y-AXIS
		ELSE
		CALL AXIS(0.,0.,YTITL,IY+NADD,YL,90.,YM,DY,N1,N2,IC)  !Y-AXIS
		IF (JF.EQ.10) CALL AXIS(ABS(XAXL),0.,YTITL,-IY-100-NADD,
     $			YL,90.,YM,DY,N1,N2,IC)		!Y-AXIS
		ENDIF
	ENDIF
77	CONTINUE
	SZ=SIZE
	IF (SIZE.LE.0.0) SZ=0.1				! DEFAULT SYMBOL SIZE
	DO 79 IN=1,NN
		ISYM=NSYM(IN)
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6+IN)),0.,0)   !PEN COLOR
		DO 79 I=1,NP
		    X1=X(I,IN)
		    IF (IF.EQ.2.OR.IF.EQ.3) X1=ALOG10(ABS(X1)+1.E-25)
		    Y1=Y(I,IN)
		    IF (IF.EQ.1.OR.IF.EQ.3) Y1=ALOG10(ABS(Y1)+1.E-25)
		    X1=(X1-XM)/DX
		    Y1=(Y1-YM)/DY
		    IF (ISYM.LT.0) THEN			! DOTS ONLY
			CALL PLOT(X1,Y1,3)
			CALL PLOT(X1,Y1,2)
		    ELSE				! SYMBOLS INSTEAD
			CALL SYMBOL(X1,Y1,SZ,ISYM,0.,1,-1)
		    ENDIF
 79	CONTINUE
	CS=.21						! TITLE CHARACTER SIZE
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6)),0.,0)	! PEN COLOR
	IF (NT.NE.0.AND.JF.NE.0) THEN			! PLOT TITLE
		XP=0.0
		YP=0.0
		CALL SYMBOL(XP,YP,CS,TITLE,
     $			0.,IABS(NT),-3)			! TITLE LENGTH
		XP=ABS(XAXL/2.)-XP/2.
		IF (XP.LT.0.) XP=0.
		CALL SYMBOL(XP,ABS(YAXL)+.15,CS,TITLE,
     $			0.,IABS(NT),-1)			! PLOT TITLE
	ENDIF
	CALL PLOT(0.,0.,3)
	IF (IFLAG.GT.0) THEN
		CALL CTERM(2)				! ASK IF CLEAR SCREN
		CALL PLOTND				! CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
	ENDIF
	IF (IFLAG.LT.0) THEN
		REPEAT=.TRUE.
		CALL CTERM(1)				! RETURN TO TEXT MODE
	ENDIF
	RETURN
	END
C
C *************************************************************************
C
	SUBROUTINE CNTRPLT(V,NDX,NDY,NX,NY,NLEVELS,ASTART,AEND,IFLAG,
     1		XAXL,YAXL,XTITL,NXT,YTITL,NYT,
     2		TITLE,NT,XMIN,XMAX,YMIN,YMAX,ICOL,ILINE)
C
C	CREATED BY D. LONG    NOV, 1983	AT JPL
C	MODIFIED BY D. LONG   JAN, 1985 AT JPL + ADDED DIM OF V TO ARG LIST
C	MODIFIED BY D. LONG   FEB, 1986 AT JPL + ADDED LINE TYPE ARRAY
C	MODIFIED BY D. LONG   MAY, 1986 AT JPL + INCLUDE CONTOUR LIST USAGE
C
C	MASTER ROUTINE TO PLOT A CONTOUR PLOT WITH LOG/LINEAR AXIS
C	ROUTINE USES CELL ORIENTED, LINEAR INTERPOLATION
C
C	V	REAL DATA VALUE ARRAY DIMENSIONED V(NDX,NDY)
C	NDX,NDY	INT  DIMENSIONS OF V
C	NX	INT  NUMBER OF X VALUES
C	NY	INT  NUMBER OF Y VALUES
C	NLEVELS REAL NUMBER OF UNIFORMLY SPACED CONTOUR LEVELS BETWEEN
C			 VALUES ASTART AND AEND.  Jth CONTOUR IS
C			 (J-1)*(AEND-ASTART)/(NL-1)+ASTART
C			IF NLEVELS < 0 THEN MIN(V) AND MAX(V) ARE USED
C			 AS ASTART AND AEND VALUES
C			IF NLEVELS = 0 THEN ASTART IS USED CONTOUR LIST 
C			 WITH INT(AEND) THE NUMBER OF CONTOURS
C	ASTART  REAL STARTING VALUE OF CONTOUR PLOT LEVELS (NLEVELS<>0)
C		     CONTOUR LIST (NLEVELS=0) DIMENSIONED ASTART(INT(AEND))
C	AEND    REAL ENDING VALUE OF CONTOUR PLOT LEVELS (NLEVELS<>0)
C		     NUMBER OF CONTOURS IN ASTART (NLEVELS=0)
C	IFLAG	INT
C		  (MAG) >10000 REPEAT PLOTTING BUT DO NOT INTIALIZE PLOTTER
C			< 0  REPEAT PLOTTING (DON'T CLOSE PLOTTER OUTPUT)
C			= 0  CLOSE PLOTTER OUTPUT--DO NOT PRODUCE PLOT
C			> 0  SINGLE PLOT OUTPUT ONLY (PLOTTER OUTPUT CLOSED)
C				NOTE: AXIS MAY BE LOG, BUT POINTS ARE PLOTTED 
C				      LINEARILY SPACED
C	  (ONE'S DIGIT) = 1 X AXIS LINEAR, Y AXIS LOGRITHMIC (BASE 10)
C	  (ONE'S DIGIT) = 2 X AXIS LOGRITHMIC,Y AXIS LINEAR
C	  (ONE'S DIGIT) = 3 X AXIS LOGRITHMIC,Y AXIS LOGRITHMIC
C	  (ONE'S DIGIT) = 4 X AXIS LINEAR, Y AXIS LINEAR
C	  (TEN'S DIGIT) = 0 NO GRID OR AXIS
C	  (TEN'S DIGIT) = 1 PLOT BOX WITH AXIS TICKS
C	  (TEN'S DIGIT) = 2 PLOT SOLID CARTESIAN GRID
C	  (TEN'S DIGIT) = 3 PLOT TICKED CARTESIAN GRID W/O BOX
C	  (TEN'S DIGIT) = 4 PLOT TICKED CARTESIAN GRID WITH BOX
C	  (TEN'S DIGIT) = 5 PLOT BOX WITH AXIS TICKS AND TICKED CARTESIAN GRID
C	  (TEN'S DIGIT) = 6 PLOT W/O BOX OR GRID BUT INCLUDE AXISES
C	  (TEN'S DIGIT) = 7 PLOT SOLID LOGARITHMIC GRID 
C	  (TEN'S DIGIT) = 8 PLOT DOTTED LOGARITHMIC GRID 
C	  (TEN'S DIGIT) = 9 PLOT TICKED LOGARITHMIC GRID 
C     (HUNDRED'S DIGIT) = 0 ASK WHICH SCREEN DEVICE TO USE
C		      <>0 SCREEN DEVICE CODE NUMBER
C	XAXL	REAL  X AXIS LENGTH IN INCHES
C			> 0  USE INPUT VALUE AXIS SCALING
C			< 0  USE SMOOTHED AXIS SCALING
C	YAXL	REAL  Y AXIS LENGTH IN INCHES
C			> 0  USE INPUT VALUE SCALING
C			< 0  USE SMOOTHED AXIS SCALING
C	XTITL	CHAR  X AXIS TITLE
C	NXT	INT   NUMBER OF CHARACTERS IN X AXIS TITLE STRING
C			< 0  TICKS ON INSIDE OF AXIS
C			= 0  NO AXIS
C			> 0  TICKS ON TITLE SIDE OF AXIS
C	YTITL	CHAR  Y AXIS TITLE
C	NYT	INT   NUMBER OF CHARACTERS IN Y AXIS TITLE STRING
C			< 0  TICKS ON INSIDE OF AXIS
C			= 0  NO AXIS
C			> 0  TICKS ON TITLE SIDE OF AXIS
C	TITLE	CHAR  PLOT TITLE
C	NT	INT   NUMBER OF CHARACTERS IN PLOT TITLE
C			= 0  NO TITLE
C			< 0  USE PEN COLOR ARRAY
C			IF ABS(NT)/100 > 0 THEN USE LINE TYPE ARRAY
C	XMIN	REAL  MINIMUM VALUE DISPLAYED ON X AXIS
C	XMAX	REAL  MAXIMUM VALUE DISPLAYED ON X AXIS
C	YMIN	REAL  MINIMUM VALUE DISPLAYED ON Y ARRAY
C	YMAX	REAL  MAXIMUM VALUE DISPLAYED ON Y ARRAY
C	ICOL	INT   ARRAY OF PEN COLORS DIMENSIONED ICOL(5+NLEVELS)
C			ICOL(1) = GRID COLOR
C			ICOL(2) = AXIS LINE COLOR
C			ICOL(3) = AXIS NUMBERS COLOR
C			ICOL(4) = AXIS TITLE COLOR
C			ICOL(5) = AXIS EXPONENT COLOR
C			ICOL(6) = TITLE COLOR (COLOR UPON RETURN)
C			ICOL(7) = CONTOUR LEVEL 1
C			ICOL(8) = CONTOUR LEVEL 2
C			   .        .      .   
C			ICOL(6+NLEVELS) = CONTOUR LEVEL NLEVELS
C	ILINE	INT  ARRAY OF PEN TYPES FOR CONTOURS
C
	INTEGER XTITL(1),YTITL(1),TITLE(1)
	REAL V(NDX,NDY),PY(2),ASTART(1)
	LOGICAL REPEAT
	INTEGER PL,ICOL(1),ILINE(1),IC(4)
	COMMON /CCNTRPLT/XM,DX,YM,DY
	DATA REPEAT/.FALSE./
	PL=3					!PRINTER DATA FILE= FOR003.DAT
	IF (IFLAG.EQ.0) THEN
		IF (REPEAT) CALL PLOTND !CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
		RETURN
	ENDIF
	JF=IABS(IFLAG)
	IF (.NOT.REPEAT.AND.JF.LT.10000) THEN
		ILU=-(JF/100)			!SCREEN DEVICE, CLEAR SCREEN
		CALL FRAME(PL,ILU,1.2,1.2,1.)	!INTIALIZE PLOT PACKAGE
	ELSE
		CALL CTERM(-1)			!RESTORE PLOT MODE
C		CALL NEWPAGE			!NEW PAGE
		JF=MOD(JF,100)
	ENDIF
	JF=MOD(JF,100)
	IF=JF
	IF (IF.GT.10) IF=MOD(IF,10)
	JF=JF-IF
	NGX=ANINT(ABS(XAXL))				!GRID SIZES
	NGY=ANINT(ABS(YAXL))
	PY(1)=XMIN
	PY(2)=XMAX
	CALL SCALE(PY,ABS(XAXL),2,1,1,XM2,DX2)
	IF (IF.EQ.2.OR.IF.EQ.3) THEN
		CALL SCALG(PY,ABS(XAXL),2,1,1,XM,DX)	!SMOOTH SCALE FACTORS
		IK=-1
		GDX=1./DX
		NGX=DX*ABS(XAXL)
		INX=-1
	ELSE
		CALL SCALE(PY,ABS(XAXL),2,1,1,XM,DX)	!SMOOTH SCALE FACTORS
		IK=0
		GDX=1.
		INX=1
	ENDIF
	IF (XAXL.GT.0.0) THEN				!INPUT SCALING
		XM2=XMIN
		DX2=(XMAX-XMIN)/ABS(XAXL)
		IF (IF.EQ.2.OR.IF.EQ.3) THEN
			XM=ALOG10(ABS(XMIN)+1.E-25)
			IF (XM.NE.AINT(XM)) XM=AINT(XM)-1.
			DX=AINT(ALOG10(ABS(XMAX)+1.E-25))+1.
			DX=(DX-XM)/ABS(XAXL)
			GDX=1./DX
			NGX=DX*ABS(XAXL)
		ELSE
			XM=XMIN
			DX=(XMAX-XMIN)/ABS(XAXL)
			GDX=1.
		ENDIF
	ENDIF
	PY(1)=YMIN
	PY(2)=YMAX
	CALL SCALE(PY,ABS(YAXL),2,1,1,YM2,DY2)
	IF (IF.EQ.1.OR.IF.EQ.3) THEN
		CALL SCALG(PY,ABS(YAXL),2,1,1,YM,DY)	!SMOOTH SCALE FACTORS
		IK=-1+IK
		GDY=1./DY
		NGY=DY*ABS(YAXL)
		INY=-1
	ELSE
		CALL SCALE(PY,ABS(YAXL),2,1,1,YM,DY)	!SMOOTH SCALE FACTORS
		IK=1+IK
		GDY=1.
		INY=1
	ENDIF
	IF (YAXL.GT.0.0) THEN				!INPUT SCALING
		YM2=YMIN
		DY2=(YMAX-YMIN)/ABS(YAXL)
		IF (IF.EQ.1.OR.IF.EQ.3) THEN
			YM=ALOG10(ABS(YMIN)+1.E-25)
			IF (YM.NE.AINT(YM)) YM=AINT(YM)-1.
			DY=AINT(ALOG10(ABS(YMAX)+1.E-25))+1.
			DY=(DY-YM)/ABS(YAXL)
			GDY=1./DY
			NGY=DY*ABS(YAXL)
		ELSE
			YM=YMIN
			DY=(YMAX-YMIN)/ABS(YAXL)
			GDY=1.
		ENDIF
	ENDIF
	IF (JF.EQ.0) GOTO 77		!NO AXIS
	IF (JF.EQ.60) GOTO 76		!NO GRID
	IF (JF.GT.60) THEN		!LOGRITHMIC GRID
		II=0
		IF (JF.EQ.70) II=1
		IF (JF.EQ.80) II=2
		CALL LGRID(0.,0.,GDX,GDY,INX*NGX,INY*NGY,II)
		GOTO 76
	ENDIF
	IF (JF.GE.20) THEN		!CARTESIAN GRID
		IF (JF.GE.30) NGX=-NGX
		IF (JF.GE.40) NGY=-NGY
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(1)),0.,0) !PEN COLOR
		CALL GRID(0.,0.,GDX,GDY,NGX,NGY)	!PRODUCE GRID
		IF (JF.EQ.50) JF=10
	ENDIF
76	NADD=0
	IF (NT.LT.0) THEN
		NADD=100000		!PEN COLOR
		IC(1)=ICOL(2)
		IC(2)=ICOL(3)
		IC(3)=ICOL(4)
		IC(4)=ICOL(5)
	ENDIF
	IX=IABS(NXT)
	XL=ABS(XAXL)*SIGN(1.,FLOAT(NXT))		!AXIS LENGTH WITH TICK INFOR
	IF (NXT.NE.0) THEN
		IF (IF.EQ.2.OR.IF.EQ.3) THEN
		CALL LGAXS(0.,0.,XTITL,-IX-NADD,XL,0.,XM,DX,IC) !X-AXIS
		IF (JF.EQ.10) CALL LGAXS(0.,ABS(YAXL),XTITL,IX+100+NADD,
     $			XL,0.,XM,DX,IC) !X-AXIS
		ELSE
		CALL AXIS(0.,0.,XTITL,-IX-NADD,XL,0.,XM,DX,N1,N2,IC)  !X-AXIS
		IF (JF.EQ.10) CALL AXIS(0.,ABS(YAXL),XTITL,IX+100+NADD,
     $			XL,0.,XM,DX,N1,N2,IC)  !X-AXIS
		ENDIF
	ENDIF
	IY=IABS(NYT)+1000
	YL=ABS(YAXL)*SIGN(1.,FLOAT(NYT))
	IF (NYT.NE.0) THEN
		IF (IF.EQ.1.OR.IF.EQ.3) THEN
		CALL LGAXS(0.,0.,YTITL,IY+NADD,YL,90.,YM,DY,IC) !Y-AXIS
		IF (JF.EQ.10) CALL LGAXS(ABS(XAXL),0.,YTITL,-IY-100-NADD,
     $			YL,90.,YM,DY,IC) !Y-AXIS
		ELSE
		CALL AXIS(0.,0.,YTITL,IY+NADD,YL,90.,YM,DY,N1,N2,IC)  !Y-AXIS
		IF (JF.EQ.10) CALL AXIS(ABS(XAXL),0.,YTITL,-IY-100-NADD,
     $			YL,90.,YM,DY,N1,N2,IC)	!Y-AXIS
		ENDIF
	ENDIF
C
77	CONTINUE
	AE=AEND
	AS=ASTART(1)
	NL=IABS(NLEVELS)
	IF (NL.EQ.0) THEN
		NL=IFIX(ABS(AEND)+0.5)
		IF (NL.EQ.0) RETURN
	ENDIF
	IF (NLEVELS.LT.0) THEN
		DO 65 IX=1,IABS(NX)
			DO 65 IY=1,NY
				AE=MAX(AE,V(IX,IY))
				AS=MIN(AS,V(IX,IY))
65		CONTINUE
	ENDIF
	DA=0.
	IF (NL.GT.1) DA=(AE-AS)/FLOAT(NL-1)
	DXX=(XMAX-XMIN)/FLOAT(IABS(NX)-1)
	XMM=XMIN-XM2
	DYY=(YMAX-YMIN)/FLOAT(NY-1)
	YMM=YMIN-YM2
	DO 100 IL=1,NL
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6+IL)),0.,0)	! CONTOUR COLOR
		IF (IABS(NT)/100.GT.0) CALL NEWPEN(ILINE(IL))	! LINE TYPE
		TV=AS+FLOAT(IL-1)*DA
		IF (NLEVELS.EQ.0) TV=ASTART(IL)
		DO 50 IY=1,IABS(NY)-1
			Y1=(FLOAT(IY-1)*DYY+YMM)/DY2
			Y2=(FLOAT(IY)*DYY+YMM)/DY2
			IYY=IY
			IF (IY.GT.1) IYY=IYY-1
			IY2=IY+1
			IF (IY2.LT.NY) IY2=IY2+1
			DO 50 IX=1,IABS(NX)-1
				X1=(FLOAT(IX-1)*DXX+XMM)/DX2
				X2=(FLOAT(IX)*DXX+XMM)/DX2
				IXX=IX
				IF (IX.GT.1) IXX=IXX-1
				IX2=IX+1
				IF (IX2.LT.IABS(NX)) IX2=IX2+1
				CALL CNCELPLT(X1,Y1,X2,Y2,TV,V(IX,IY),
     $				V(IX,IY+1),V(IX+1,IY+1),V(IX+1,IY),
     $				V(IXX,IYY),V(IXX,IY2),V(IX2,IY2),V(IX2,IYY))
 50		CONTINUE
100	CONTINUE
C
	IF (IABS(NT)/100.GT.0) CALL NEWPEN(0)		!RESET LINE TYPE
	CS=.21						!TITLE CHARACTER SIZE
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6)),0.,0)	!PEN COLOR
	IF (NT.NE.0.AND.JF.NE.0) THEN			!TITLE
		XP=0.0
		YP=0.0
		CALL SYMBOL(XP,YP,CS,TITLE,
     $			0.,MOD(IABS(NT),100),-3)	!TITLE LENGTH
		XP=ABS(XAXL/2.)-XP/2.
		IF (XP.LT.0.) XP=0.
		CALL SYMBOL(XP,ABS(YAXL)+.15,CS,TITLE,
     $			0.,MOD(IABS(NT),100),-1)	!PLOT TITLE
	ENDIF
	CALL PLOT(0.,0.,3)
	IF (IFLAG.GT.0) THEN
		CALL CTERM(2)				!ASK IF CLEAR SCREN
		CALL PLOTND				!CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
	ENDIF
	IF (IFLAG.LT.0) THEN
		REPEAT=.TRUE.
		CALL CTERM(1)				!RETURN TO TEXT MODE
	ENDIF
	RETURN
	END
C
	SUBROUTINE CNCELPLT(X1,Y1,X2,Y2,TV,V1,V2,V3,V4,V5,V6,V7,V8)
C
C	CREATED BY D. LONG     NOV, 1983	AT JPL
C	SUBPROGRAM OF CNTRPLT
C	COMPUTES AND PLOTS CELL SECTIONED CONTOURS
C
C	POINT ID MAP:
C			  (2)
C			2.   3.
C		    (1)	       (4)
C			1.   4.
C			  (8)
C
	INTEGER SEGCODE
C
	IF=SEGCODE(Y1,Y2,V1,V2,TV,YI1)
	IF=IF+2*SEGCODE(X1,X2,V2,V3,TV,XI2)
	IF=IF+4*SEGCODE(Y2,Y1,V3,V4,TV,YI3)
	IF=IF+8*SEGCODE(X2,X1,V4,V1,TV,XI4)
C
	GOTO (50,50,50,103,50,105,106,107,50,109,110,
     $		111,112,113,114,115) IF+1
	GOTO 50
103	CONTINUE
	CALL PLOT(X1,YI1,3)
	CALL PLOT(XI2,Y2,2)
	GOTO 50
105	CONTINUE
	CALL PLOT(X1,YI1,3)
	CALL PLOT(X2,YI3,2)
	GOTO 50
106	CONTINUE
	CALL PLOT(XI2,Y2,3)
	CALL PLOT(X2,YI3,2)
	GOTO 50
107	CONTINUE
	IF (V3.EQ.TV) GOTO 103
	GOTO 106
109	CONTINUE
	CALL PLOT(X1,YI1,3)
	CALL PLOT(XI4,Y1,2)
	GOTO 50
110	CONTINUE
	CALL PLOT(XI4,Y1,3)
	CALL PLOT(XI2,Y2,2)
	GOTO 50
111	CONTINUE
	IF (V1.EQ.TV) GOTO 103
	GOTO 109
112	CONTINUE
	CALL PLOT(XI4,Y1,3)
	CALL PLOT(X2,YI3,2)
	GOTO 50
113	CONTINUE
	IF (V1.EQ.TV) GOTO 112
	GOTO 109
114	CONTINUE
	IF (V3.EQ.TV) GOTO 112
	GOTO 106
115	CONTINUE
	IF (V1.EQ.TV) GOTO 50
	C1=POLY1INT(V5,V1,V3,V7,1.5)
	C2=POLY1INT(V6,V2,V4,V8,1.5)
	C=(C1+C2)/2.
	IF (C.GT.TV) THEN
		IF (V1.GT.TV) THEN
			CALL PLOT(X1,YI1,3)
			CALL PLOT(XI2,Y2,2)
			GOTO 112
		ELSE
			CALL PLOT(X1,YI1,3)
			CALL PLOT(XI4,Y1,2)
			GOTO 106
		ENDIF
	ELSE
		IF (V1.LT.TV) THEN
			CALL PLOT(X1,YI1,3)
			CALL PLOT(XI2,Y2,2)
			GOTO 112
		ELSE
			CALL PLOT(X1,YI1,3)
			CALL PLOT(XI4,Y1,2)
			GOTO 106
		ENDIF
	ENDIF
 50	RETURN
	END
C
	INTEGER FUNCTION SEGCODE(X1,X2,V1,V2,TV,X0)
C
C	CREATED BY D. LONG  NOV, 1983 	AT JPL
C	SUBFUNCTION OF CNTRPLT
C	DETERMINES IF INTERSECTION AND COMPUTES LOCATION
C
	SC=0
	IF (MAX(V1,V2).GE.TV.AND.MIN(V1,V2).LE.TV) THEN
		SC=1
		IF (V2.NE.V1) THEN
			X0=(X2-X1)*(TV-V1)/(V2-V1)+X1
		ELSE
			X0=X1
		ENDIF
	ENDIF
	SEGCODE=SC
	RETURN
	END
C
	REAL FUNCTION POLY1INT(V0,V1,V2,V3,D)
C
C	CREATED BY D. LONG     NOV, 1983	AT JPL
C	SUBFUNCTION OF CNTRPLT
C	DOES LEAST SQUARES CURVE INTERPLOATION
C	V0..V3 ASSUMMED EQUALLY SPACED AND 1.0 DISTANCE
C	D IS POINT OF INTERPOLATED VALUE
C
	C0= 0.95*V0+0.15*V1-0.15*V2+0.05*V3
	C1=-1.05*V0+0.65*V1+0.85*V2-0.45*V3
	C2= 0.25*V0-0.25*V1-0.25*V2+0.25*V3
C
	POLY1INT=C0+C1*D+D2*D**2
	RETURN
	END
C
C *************************************************************************
C
	SUBROUTINE PLOTLGX(X,Y,NND,NPD,NN,NP,IFLAG,NSYM,XAXL,YAXL,
     1		NMX,NNX,MLX,TSX,NDX,SMX,NMY,NNY,MLY,TSY,NDY,SMY,
     2		XTITL,NXT,YTITL,NYT,TITLE,NT,XMIN,XMAX,YMIN,YMAX,
     3		ICOL,ILINE)
C
C	CREATED BY D. LONG       FEB, 1984	AT JPL
C	MODIFIED BY D. LONG   FEB, 1986 AT JPL + ADDED LINE TYPE ARRAY
C
C	ROUTINE TO PLOT SEVERAL LINES OF DATA IN LOG/LINEAR COMBINATION
C	AXIS FLEXIBILITY IS PROVIDED
C
C	X	REAL X VALUE ARRAY
C	Y	REAL Y DATA ARRAY DIMENSION Y(NPD,NND)
C	NND	INT  DIMENSION OF Y
C	NPD	INT  DIMENSION OF Y
C	NN	INT  # NUMBER OF LINES TO PLOT
C	NP	INT  # OF POINTS IN IN LINE
C	IFLAG	INT
C	  (MAG) >10000 REPEAT PLOTTING BUT DO NOT INTIALIZE PLOTTER
C		< 0  REPEAT PLOTTING (DON'T CLOSE PLOTTER OUTPUT)
C		= 0  CLOSE PLOTTER OUTPUT--DO NOT PRODUCE PLOT
C		> 0  SINGLE PLOT OUTPUT ONLY (PLOTTER OUTPUT CLOSED)
C	  (ONE'S DIGIT) = 1 X LINEAR, Y LOGRITHMIC (BASE 10)
C	  (ONE'S DIGIT) = 2 X LOGRITHMIC,Y LINEAR
C	  (ONE'S DIGIT) = 3 X LOGRITHMIC,Y LOGRITHMIC
C	  (ONE'S DIGIT) = 4 X LINEAR, Y LINEAR
C	  (TEN'S DIGIT) = 0 NO AXIS OR GRID 
C	  (TEN'S DIGIT) = 1 PLOT BOX WITH AXIS TICKS
C	  (TEN'S DIGIT) = 2 PLOT SOLID GRID
C	  (TEN'S DIGIT) = 3 PLOT TICKED GRID W/O BOX
C	  (TEN'S DIGIT) = 4 PLOT TICKED GRID WITH BOX
C	  (TEN'S DIGIT) = 5 PLOT BOX WITH AXIS TICKS AND TICKED GRID
C	  (TEN'S DIGIT) = 6 PLOT W/O BOX OR GRID BUT USE AXISES
C	  (TEN'S DIGIT) = 7 PLOT SOLID LOGRITHMIC GRID
C	  (TEN'S DIGIT) = 8 PLOT DOTTED LOGRITHMIC GRID
C	  (TEN'S DIGIT) = 9 PLOT TICKED LOGRITHMIC GRID
C     (HUNDRED'S DIGIT) = 0 ASK WHICH SCREEN DEVICE TO USE
C			<>0 SCREEN DEVICE NUMBER CODE
C	NSYM	INT   NUMBER OF POINTS BETWEEN SYMBOLS
C		      < 0  SYMBOLS ONLY, NO LINE
C		      = 0  NO SYMBOLS, LINE ONLY
C		      > 0 NUMBER OF POINTS BETWEEN SYMBOLS
C	XAXL	REAL  X AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C	YAXL	REAL  Y AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C
C NOTE: 	XMIN,XMAX,YMIN,YMAX ARE ONLY REQUIRED IF XAXL OR YAXL < 0
C
C	NMX...SMY    PARAMETERS FOR PLOT AXISES (SEE ROUTINE AXIS2)
C			ALL PARAMETERS MUST BE PRESENT AND WILL BE USED
C	XTITL	CHAR  X AXIS TITLE
C	NXT	INT   NUMBER OF CHARACTERS IN X AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	YTITL	CHAR  Y AXIS TITLE
C	NYT	INT   NUMBER OF CHARACTERS IN Y AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	TITLE	CHAR  PLOT TITLE
C	NT	INT   NUMBER OF CHARACTERS IN PLOT TITLE
C		= 0  NO TITLE
C		< 0  USE PEN COLOR ARRAY
C			IF IABS(NT)/100)>1 USE LINE TYPE ARRAY
C	XMIN	REAL  MINIMUM VALUE DISPLAYED ON X AXIS
C	XMAX	REAL  MAXIMUM VALUE DISPLAYED ON X AXIS
C	YMIN	REAL  MINIMUM VALUE OF Y ARRAY
C	YMAX	REAL  MAXIMUM VALUE OF Y ARRAY
C	ICOL	INT   ARRAY OF PEN COLORS PEN DIMENSIONED ICOL(5+NN)
C			ICOL(1) = GRID COLOR
C			ICOL(2) = AXIS LINE COLOR
C			ICOL(3) = AXIS NUMBERS COLOR
C			ICOL(4) = AXIS TITLE COLOR
C			ICOL(5) = AXIS EXPONENT COLOR
C			ICOL(6) = TITLE COLOR (COLOR UPON RETURN)
C			ICOL(7) = LINE COLOR 1
C			ICOL(8) = LINE COLOR 2
C			   .	     .	     3
C	ILINE	INT  ARRAY OF LINE TYPES
C
	INTEGER XTITL(1),YTITL(1),TITLE(1)
	REAL Y(NPD,NND),X(NPD),PY(2)
	LOGICAL REPEAT
	INTEGER PL,ICOL(1),IC(4),ILINE(1)
	COMMON /CPLOTLGX/XM,DX,YM,DY
	DATA REPEAT/.FALSE./
	PL=3					! PRINTER DATA FILE= FOR003.DAT
	IF (IFLAG.EQ.0) THEN
		IF (REPEAT) CALL PLOTND !CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
		RETURN
	ENDIF
	JF=IABS(IFLAG)
	IF (.NOT.REPEAT.AND.JF.LT.10000) THEN
		ILU=-(JF/100)			!SCREEN DEVICE, CLEAR SCREEN
		CALL FRAME(PL,ILU,1.2,1.2,1.)	!INTIALIZE PLOT PACKAGE
	ELSE
		CALL CTERM(-1)			!RESTORE PLOT MODE
C		CALL NEWPAGE			!NEW PAGE
		JF=MOD(JF,100)
	ENDIF
	JF=MOD(JF,100)
	IF=JF
	IF (IF.GT.10) IF=MOD(IF,10)
	JF=JF-IF
	NX=ABS(ANINT(XAXL))				!GRID SIZES
	NY=ABS(ANINT(YAXL))
	IF (XAXL.GT.0.0) THEN				!INPUT SCALING
	    XM=X(1)
	    DX=X(1)
	    DO 5 I=2,NP
		XM=MAX(X(I),XM)
		DX=MIN(X(I),DX)
 5	    CONTINUE
	    PY(1)=XM
	    PY(2)=DX
	    IF (IF.EQ.2.OR.IF.EQ.3) THEN
		CALL SCALG(PY,ABS(XAXL),2,1,1,XM,DX)	!SMOOTH SCALE FACTORS
		IK=-1
		GDX=1./DX
		NX=DX*ABS(XAXL)
		INX=-1
	    ELSE
		CALL SCALE(PY,ABS(XAXL),2,1,1,XM,DX)	!SMOOTH SCALE FACTORS
		IK=0
		GDX=1.
		INX=1
	    ENDIF
	ELSE
	    IF (IF.EQ.2.OR.IF.EQ.3) THEN
		XM=(ABS(XMIN)+1.E-25)
		IF (XM.NE.AINT(XM)) XM=AINT(XM)-1.
		DX=AINT(ALOG10(ABS(XMAX)+1.E-25))+1.
		DX=(DX-XM)/ABS(XAXL)
		GDX=1./DX
		IK=-1
		NX=DX*ABS(XAXL)
		INX=-1
	    ELSE
		XM=XMIN
		DX=(XMAX-XMIN)/ABS(XAXL)
		GDX=1.
		IK=0
		INX=1
	    ENDIF
	ENDIF
	IF (YAXL.GT.0.0) THEN				!INPUT SCALING
	    YM=Y(1,1)
	    DY=Y(1,1)
	    DO 6 IN=1,NN
		DO 6 I=1,NP
		    YM=MAX(Y(I,IN),YM)
		    DY=MIN(Y(I,IN),DY)
6		CONTINUE
	    PY(1)=YM
	    PY(2)=DY
	    IF (IF.EQ.1.OR.IF.EQ.3) THEN
		CALL SCALG(PY,ABS(YAXL),2,1,1,YM,DY)	!SMOOTH SCALE FACTORS
		IK=-1+IK
		GDY=1./DY
		NY=DY*ABS(YAXL)
		INY=-1
	    ELSE
		CALL SCALE(PY,ABS(YAXL),2,1,1,YM,DY)	!SMOOTH SCALE FACTORS
		IK=1+IK
		GDY=1.
		INY=1
	    ENDIF
	ELSE
	    IF (IF.EQ.1.OR.IF.EQ.3) THEN
		YM=ALOG10(ABS(YMIN)+1.E-25)
		IF (YM.NE.AINT(YM)) YM=AINT(YM)-1.
		DY=AINT(ALOG10(ABS(YMAX)+1.E-25))+1.
		DY=(DY-YM)/ABS(YAXL)
		GDY=1./DY
		NY=DY*ABS(YAXL)
		IK=-1+IK
		INY=-1
	    ELSE
		YM=YMIN
		DY=(YMAX-YMIN)/ABS(YAXL)
		IK=1+IK
		GDY=1.
		INY=1
	    ENDIF
	ENDIF
	IF (JF.EQ.0) GOTO 77		!NO AXIS OR GRID
	IF (JF.EQ.60) GOTO 76		!NO GRID
	IF (JF.GT.60) THEN		!LOGRITHMIC GRID
		II=0
		IF (JF.EQ.70) II=1
		IF (JF.EQ.80) II=2
		CALL LGRID(0.,0.,GDX,GDY,INX*NX,INY*NY,II)
		GOTO 76
	ENDIF
	IF (JF.GE.20) THEN		!CARTESIAN GRID
		IF (JF.GE.30) NX=-NX
		IF (JF.GE.40) NY=-NY
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(1)),0.,0) !PEN COLOR
		CALL GRID(0.,0.,GDX,GDY,NX,NY)		!PRODUCE GRID
		IF (JF.EQ.50) JF=10
	ENDIF
76	NADD=0
	IF (NT.LT.0) THEN
		NADD=100000		!PEN COLOR
		IC(1)=ICOL(2)
		IC(2)=ICOL(3)
		IC(3)=ICOL(4)
		IC(4)=ICOL(5)
	ENDIF
	IX=IABS(NXT)
	XL=ABS(XAXL)*SIGN(1.,FLOAT(NXT))		!AXIS LENGTH WITH TICK INFOR
	IF (NXT.NE.0) THEN
		IF (IF.EQ.2.OR.IF.EQ.3) THEN
		CALL LGAXS(0.,0.,XTITL,-IX-NADD,XL,0.,XM,DX,IC) !X-AXIS
		IF (JF.EQ.10) CALL LGAXS(0.,ABS(YAXL),XTITL,IX+100+NADD,
     $			XL,0.,XM,DX,IC) !X-AXIS
		ELSE
		CALL AXIS2(0.,0.,XTITL,-IX-NADD-10000,XL,0.,XM,DX,
     $			NMX,NNX,-IABS(MLX),TSX,NDX,SMX,IC)  !X-AXIS
		IF (JF.EQ.10) CALL AXIS2(0.,ABS(YAXL),XTITL,IX+NADD+10100,
     $			XL,0.,XM,DX,NMX,NNX,-IABS(MLX),TSX,NDX,SMX,IC)  !X-AXIS
		ENDIF
	ENDIF
	IY=IABS(NYT)+1000
	YL=ABS(YAXL)*SIGN(1.,FLOAT(NYT))
	IF (NYT.NE.0) THEN
		IF (IF.EQ.1.OR.IF.EQ.3) THEN
		CALL LGAXS(0.,0.,YTITL,IY+NADD,YL,90.,YM,DY,IC) !Y-AXIS
		IF (JF.EQ.10) CALL LGAXS(ABS(XAXL),0.,YTITL,-IY-100-NADD,
     $			YL,90.,YM,DY,IC) !Y-AXIS
		ELSE
		CALL AXIS2(0.,0.,YTITL,IY+NADD+10000,YL,90.,YM,DY,
     $			NMY,NNY,-IABS(MLY),TSY,NDY,SMY,IC)  		!Y-AXIS
		IF (JF.EQ.10) CALL AXIS2(ABS(XAXL),0.,YTITL,-IY-NADD-10100,
     $			YL,90.,YM,DY,NMY,NNY,-IABS(MLY),TSY,NDY,SMY,IC)  !Y-AXIS
		ENDIF
	ENDIF
77	IF (IK.EQ.1) THEN
	    DO 78 IN=1,NN
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6+IN)),0.,0)!PEN COLOR
		IF (IABS(NT)/100.GT.0) CALL NEWPEN(ILINE(IN)) !LINE TYPE
		CALL LINE(X,Y(1,IN),NP,1,NSYM,IN-1,1,1,XM,DX,YM,DY) !PLOT DATA
78	    CONTINUE
	ELSE
	    IF (IK.EQ.-1) IK=1				    !CORRECT FLAG
	    IF (IK.EQ.0) IK=-1
	    DO 79 IN=1,NN
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6+IN)),0.,0)!PEN COLOR
		IF (IABS(NT)/100.GT.0) CALL NEWPEN(ILINE(IN)) !LINE TYPE
		CALL LGLIN(X,Y(1,IN),NP,1,NSYM,IN-1,IK,1,1,XM,DX,YM,DY)	  !PLOT DATA
79	    CONTINUE
	ENDIF
	IF (IABS(NT)/100.GT.0) CALL NEWPEN(0)		!RESET LINE TYPE
	CS=.21						!TITLE CHARACTER SIZE
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6)),0.,0)	!PEN COLOR
	IF (NT.NE.0.AND.JF.NE.0) THEN			!TITLE
		XP=0.0
		YP=0.0
		CALL SYMBOL(XP,YP,CS,TITLE,
     $			0.,MOD(IABS(NT),100),-3)	!TITLE LENGTH
		XP=ABS(XAXL/2.)-XP/2.
		IF (XP.LT.0.) XP=0.
		CALL SYMBOL(XP,ABS(YAXL)+.15,CS,TITLE,
     $			0.,MOD(IABS(NT),100),-1)	!PLOT TITLE
	ENDIF
	CALL PLOT(0.,0.,3)
	IF (IFLAG.GT.0) THEN
		CALL CTERM(2)				!ASK IF CLEAR SCREN
		CALL PLOTND				!CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
	ENDIF
	IF (IFLAG.LT.0) THEN
		REPEAT=.TRUE.
		CALL CTERM(1)				!RETURN TO TEXT MODE
	ENDIF
	RETURN
	END
C
C *************************************************************************
C
	SUBROUTINE SPLOTS(X,Y,NND,NPD,NN,NP,IFLAG,NOPT,AS,
     1		XAXL,YAXL,XTITL,NXT,YTITL,NYT,TITLE,NT,
     2		XMIN,XMAX,YMIN,YMAX,ICOL)
C
C	CREATED BY D. LONG       MAR, 1984	AT JPL
C
C	ROUTINE TO PLOT SEVERAL LINES OF DATA IN LOG/LINEAR COMBINATION
C	AXIS FLEXIBILITY IS PROVIDED -- SEE ROUTINE SPLOTSX FOR VARIABLE
C	DESCRIPTION
C
	DIMENSION X(1),Y(1),ICOL(1)
	INTEGER XTITL(1),YTITL(1),TITLE(1)
	COMMON /CSPLOTS/XM,DX,YM,DY
	COMMON /CSPLOTSX/XM1,DX1,YM1,DY1
	IF (XAXL.LT.0.0.OR.NT.LT.0) THEN
		XMN=XMIN
		XMX=XMAX
		IF (YAXL.LT.0.0.OR.NT.LT.0) THEN
			YMN=YMIN
			YMX=YMAX
		ENDIF
	ENDIF
	NX=ABS(XAXL)+.5
	NY=ABS(YAXL)+.5
	IF (NT.LT.0) THEN
	   CALL SPLOTSX(X,Y,NND,NPD,NN,NP,IFLAG,NOPT,AS,XAXL,YAXL,
     1		0,0,NX,0.15,1,.1,0,0,NY,0.15,1,.1,
     2		XTITL,NXT,YTITL,NYT,TITLE,NT,XMN,XMX,YMN,YMX,ICOL)
	ELSE
	   CALL SPLOTSX(X,Y,NND,NPD,NN,NP,IFLAG,NOPT,AS,XAXL,YAXL,
     1		0,0,NX,0.15,1,.1,0,0,NY,0.15,1,.1,
     2		XTITL,NXT,YTITL,NYT,TITLE,NT,XMN,XMX,YMN,YMX)
	ENDIF
	XM=XM1
	DX=DX1
	YM=YM1
	DY=DY1
	RETURN
	END
C
	SUBROUTINE SPLOTSX(X,Y,NND,NPD,NN,NP,IFLAG,NOPT,AS,
     1		XAXL,YAXL,NMX,NNX,MLX,TSX,NDX,SMX,NMY,NNY,MLY,
     2		TSY,NDY,SMY,XTITL,NXT,YTITL,NYT,TITLE,NT,
     3		XMIN,XMAX,YMIN,YMAX,ICOL)
C
C	CREATED BY D. LONG       MAR, 1984	AT JPL
C
C	ROUTINE TO PLOT SEVERAL LINES OF DATA IN LOG/LINEAR COMBINATION
C	AXIS FLEXIBILITY IS PROVIDED
C
C	X	REAL X VALUE ARRAY
C	Y	REAL Y DATA ARRAY DIMENSION Y(NPD,NND)
C	NND	INT  DIMENSION OF Y
C	NPD	INT  DIMENSION OF Y
C	NN	INT  # NUMBER OF LINES TO PLOT
C	NP	INT  # OF POINTS IN IN LINE
C	IFLAG	INT
C	  (MAG) >10000 REPEAT PLOTTING BUT DO NOT INTIALIZE PLOTTER
C		< 0  REPEAT PLOTTING (DON'T CLOSE PLOTTER OUTPUT)
C		= 0  CLOSE PLOTTER OUTPUT--DO NOT PRODUCE PLOT
C		> 0  SINGLE PLOT OUTPUT ONLY (PLOTTER OUTPUT CLOSED)
C	  (ONE'S DIGIT) = 1 X LINEAR, Y LOGRITHMIC (BASE 10)
C	  (ONE'S DIGIT) = 2 X LOGRITHMIC,Y LINEAR
C	  (ONE'S DIGIT) = 3 X LOGRITHMIC,Y LOGRITHMIC
C	  (ONE'S DIGIT) = 4 X LINEAR, Y LINEAR
C	  (TEN'S DIGIT) = 0 NO AXIS OR GRID 
C	  (TEN'S DIGIT) = 1 PLOT BOX WITH AXIS TICKS
C	  (TEN'S DIGIT) = 2 PLOT SOLID GRID
C	  (TEN'S DIGIT) = 3 PLOT TICKED GRID W/O BOX
C	  (TEN'S DIGIT) = 4 PLOT TICKED GRID WITH BOX
C	  (TEN'S DIGIT) = 5 PLOT BOX WITH AXIS TICKS AND TICKED GRID
C	  (TEN'S DIGIT) = 6 PLOT W/O BOX OR GRID BUT USE AXISES
C	  (TEN'S DIGIT) = 7 PLOT SOLID LOGRITHMIC GRID
C	  (TEN'S DIGIT) = 8 PLOT DOTTED LOGRITHMIC GRID
C	  (TEN'S DIGIT) = 9 PLOT TICKED LOGRITHMIC GRID
C     (HUNDRED'S DIGIT) = 0 ASK WHICH SCREEN DEVICE TO USE
C			<>0 SCREEN DEVICE NUMBER CODE
C	NOPT	INT  OPTION FOR POINT DISPLAY
C	  (ONE'S DIGIT) = 0 POINTS WITH NO CONNECTION
C	  (ONE'S DIGIT) = 1 LINE ONLY
C	  (ONE'S DIGIT) = 2 SYMBOLS WITH NO CONNECTION
C	  (ONE'S DIGIT) = 3 LINE CONNECTED SYMBOLS
C	  (ONE'S DIGIT) = 4 LINE FROM POINT TO X AXIS PLOTTED WITH NO SYMBOLS
C	  (ONE'S DIGIT) = 5 LINE FROM POINT TO X AXIS AND INTERPOLATED LINE
C	  (ONE'S DIGIT) = 6 LINE FROM POINT TO X AXIS PLOTTED WITH SYMBOLS
C	  (TEN'S DIGIT) = 0 NORMAL
C	  (TEN'S DIGIT) = 1 PLOT ERROR BARS USING NEXT TWO LINES AS BAR WITHS
C	  (TEN'S DIGIT) = 2 PLOT ERROR BARS WITHOUT ENDS
C     	  (HUNDRED'S) NUMBER OF POINTS BETWEEN SYMBOLS AND BARS (0=1)
C	AS	REAL  PLOT SYMBOL SIZE
C	XAXL	REAL  X AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C	YAXL	REAL  Y AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C
C NOTE: 	XMIN,XMAX,YMIN,YMAX ARE ONLY REQUIRED IF XAXL OR YAXL < 0
C
C	NMX...SMY    PARAMETERS FOR PLOT AXISES (SEE ROUTINE AXIS2)
C			ALL PARAMETERS MUST BE PRESENT AND WILL BE USED
C	XTITL	CHAR  X AXIS TITLE
C	NXT	INT   NUMBER OF CHARACTERS IN X AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	YTITL	CHAR  Y AXIS TITLE
C	NYT	INT   NUMBER OF CHARACTERS IN Y AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	TITLE	CHAR  PLOT TITLE
C	NT	INT   NUMBER OF CHARACTERS IN PLOT TITLE
C		= 0  NO TITLE
C		< 0  USE COLOR ARRAY (REQUIRES XMIN,XMAX,YMIN,YMAX TOO)
C	XMIN	REAL  MINIMUM VALUE DISPLAYED ON X AXIS
C	XMAX	REAL  MAXIMUM VALUE DISPLAYED ON X AXIS
C	YMIN	REAL  MINIMUM VALUE OF Y ARRAY
C	YMAX	REAL  MAXIMUM VALUE OF Y ARRAY
C	ICOL	INT   ARRAY OF PEN COLORS DIMENSIONED ICOL(6+NN)
C			ICOL(1) = GRID COLOR
C			ICOL(2) = AXIS LINE COLOR
C			ICOL(3) = AXIS NUMBERS COLOR
C			ICOL(4) = AXIS TITLE COLOR
C			ICOL(5) = AXIS EXPONENT COLOR
C			ICOL(6) = TITLE COLOR (COLOR UPON RETURN)
C			ICOL(7) = LINE COLOR 1
C			ICOL(8) = LINE COLOR 2
C			   .	     .	     3
C
	INTEGER XTITL(1),YTITL(1),TITLE(1)
	REAL Y(NPD,NND),X(NPD),PY(2)
	LOGICAL REPEAT
	INTEGER PL,ICOL(1),IC(4)
	COMMON /CSPLOTSX/XM,DX,YM,DY
	DATA REPEAT/.FALSE./
	PL=3					! PRINTER DATA FILE= FOR003.DAT
	IF (IFLAG.EQ.0) THEN
		IF (REPEAT) CALL PLOTND !CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
		RETURN
	ENDIF
	JF=IABS(IFLAG)
	IF (.NOT.REPEAT.AND.JF.LT.10000) THEN
		ILU=-(JF/100)			!SCREEN DEVICE, CLEAR SCREEN
		CALL FRAME(PL,ILU,1.2,1.2,1.)	!INTIALIZE PLOT PACKAGE
	ELSE
		CALL CTERM(-1)			!RESTORE PLOT MODE
C		CALL NEWPAGE			!NEW PAGE
		JF=MOD(JF,100)
	ENDIF
	JF=MOD(JF,100)
	IF=JF
	IF (IF.GT.10) IF=MOD(IF,10)
	JF=JF-IF
	NSYM=IABS(NOPT)/100
	NOPT1=MOD(IABS(NOPT),10)
	NOPT2=(MOD(IABS(NOPT),100)-NOPT1)/10
	IF (NSYM.EQ.0) NSYM=1
	NX=ABS(ANINT(XAXL))				!GRID SIZES
	NY=ABS(ANINT(YAXL))
	IF (XAXL.GT.0.0) THEN				!INPUT SCALING
	    XM=X(1)
	    DX=X(1)
	    DO 5 I=2,NP
		XM=MAX(X(I),XM)
		DX=MIN(X(I),DX)
 5	    CONTINUE
	    PY(1)=XM
	    PY(2)=DX
	    IF (IF.EQ.2.OR.IF.EQ.3) THEN
		CALL SCALG(PY,ABS(XAXL),2,1,1,XM,DX)	!SMOOTH SCALE FACTORS
		IKX=-1
		GDX=1./DX
		NX=DX*ABS(XAXL)
		INX=-1
	    ELSE
		CALL SCALE(PY,ABS(XAXL),2,1,1,XM,DX)	!SMOOTH SCALE FACTORS
		IKX=1
		GDX=1.
		INX=1
	    ENDIF
	ELSE
	    IF (IF.EQ.2.OR.IF.EQ.3) THEN
		XM=(ABS(XMIN)+1.E-25)
		IF (XM.NE.AINT(XM)) XM=AINT(XM)-1.
		DX=AINT(ALOG10(ABS(XMAX)+1.E-25))+1.
		DX=(DX-XM)/ABS(XAXL)
		GDX=1./DX
		IKX=-1
		NX=DX*ABS(XAXL)
		INX=-1
	    ELSE
		XM=XMIN
		DX=(XMAX-XMIN)/ABS(XAXL)
		GDX=1.
		IKX=1
		INX=1
	    ENDIF
	ENDIF
	IF (YAXL.GT.0.0) THEN				!INPUT SCALING
	    YM=Y(1,1)
	    DY=Y(1,1)
	    DO 6 IN=1,NN
		DO 6 I=1,NP
		    YM=MAX(Y(I,IN),YM)
		    DY=MIN(Y(I,IN),DY)
6		CONTINUE
	    PY(1)=YM
	    PY(2)=DY
	    IF (IF.EQ.1.OR.IF.EQ.3) THEN
		CALL SCALG(PY,ABS(YAXL),2,1,1,YM,DY)	!SMOOTH SCALE FACTORS
		IKY=-1
		GDY=1./DY
		NY=DY*ABS(YAXL)
		INY=-1
	    ELSE
		CALL SCALE(PY,ABS(YAXL),2,1,1,YM,DY)	!SMOOTH SCALE FACTORS
		IKY=1
		GDY=1.
		INY=1
	    ENDIF
	ELSE
	    IF (IF.EQ.1.OR.IF.EQ.3) THEN
		YM=ALOG10(ABS(YMIN)+1.E-25)
		IF (YM.NE.AINT(YM)) YM=AINT(YM)-1.
		DY=AINT(ALOG10(ABS(YMAX)+1.E-25))+1.
		DY=(DY-YM)/ABS(YAXL)
		GDY=1./DY
		NY=DY*ABS(YAXL)
		IKY=-1
		INY=-1
	    ELSE
		YM=YMIN
		DY=(YMAX-YMIN)/ABS(YAXL)
		IKY=1
		GDY=1.
		INY=1
	    ENDIF
	ENDIF
	IF (JF.EQ.0) GOTO 77		!NO AXIS OR GRID
	IF (JF.EQ.60) GOTO 76		!NO GRID
	IF (JF.GT.60) THEN		!LOGRITHMIC GRID
		II=0
		IF (JF.EQ.70) II=1
		IF (JF.EQ.80) II=2
		CALL LGRID(0.,0.,GDX,GDY,INX*NX,INY*NY,II)
		GOTO 76
	ENDIF
	IF (JF.GE.20) THEN		!CARTESIAN GRID
		IF (JF.GE.30) NX=-NX
		IF (JF.GE.40) NY=-NY
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(1)),0.,0) !PEN COLOR
		CALL GRID(0.,0.,GDX,GDY,NX,NY)		!PRODUCE GRID
		IF (JF.EQ.50) JF=10
	ENDIF
76	NADD=0
	IF (NT.LT.0) THEN
		NADD=100000		!PEN COLOR
		IC(1)=ICOL(2)
		IC(2)=ICOL(3)
		IC(3)=ICOL(4)
		IC(4)=ICOL(5)
	ENDIF
	IX=IABS(NXT)
	XL=ABS(XAXL)*SIGN(1.,FLOAT(NXT))		!AXIS LENGTH WITH TICK INFOR
	IF (NXT.NE.0) THEN
		IF (IF.EQ.2.OR.IF.EQ.3) THEN
		CALL LGAXS(0.,0.,XTITL,-IX-NADD,XL,0.,XM,DX,IC) !X-AXIS
		IF (JF.EQ.10) CALL LGAXS(0.,ABS(YAXL),XTITL,IX+100+NADD,
     $			XL,0.,XM,DX,IC) !X-AXIS
		ELSE
		CALL AXIS2(0.,0.,XTITL,-IX-NADD-10000,XL,0.,XM,DX,
     $			NMX,NNX,-IABS(MLX),TSX,NDX,SMX,IC)  !X-AXIS
		IF (JF.EQ.10) CALL AXIS2(0.,ABS(YAXL),XTITL,IX+NADD+10100,
     $			XL,0.,XM,DX,NMX,NNX,-IABS(MLX),TSX,NDX,SMX,IC)  !X-AXIS
		ENDIF
	ENDIF
	IY=IABS(NYT)+1000
	YL=ABS(YAXL)*SIGN(1.,FLOAT(NYT))
	IF (NYT.NE.0) THEN
		IF (IF.EQ.1.OR.IF.EQ.3) THEN
		CALL LGAXS(0.,0.,YTITL,IY+NADD,YL,90.,YM,DY,IC) !Y-AXIS
		IF (JF.EQ.10) CALL LGAXS(ABS(XAXL),0.,YTITL,-IY-100-NADD,
     $			YL,90.,YM,DY,IC) !Y-AXIS
		ELSE
		CALL AXIS2(0.,0.,YTITL,IY+NADD+10000,YL,90.,YM,DY,
     $			NMY,NNY,-IABS(MLY),TSY,NDY,SMY,IC)  		!Y-AXIS
		IF (JF.EQ.10) CALL AXIS2(ABS(XAXL),0.,YTITL,-IY-NADD-10100,
     $			YL,90.,YM,DY,NMY,NNY,-IABS(MLY),TSY,NDY,SMY,IC)  !Y-AXIS
		ENDIF
	ENDIF
77	NLS=1
	NNN=NN
	IF (NOPT2.GT.0) THEN
		NLS=3
		NNN=NN*NLS
	ENDIF
	DO 78 IN=1,NNN,NLS					! FOR EACH LINE
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6+2*IN-1)),0.,0)!PEN COLOR
		NPCNT=1
		NORG=3
		DO 78 II=1,NP					! FOR EACH POINT
			X1=(X(II)-XM)/DX
			IF (IKX.LT.0) X1=ALOG10(ABS(X1)+1.E-25)	! LOG X
			Y1=(Y(II,IN)-YM)/DY
			IF (IKY.LT.0) Y1=ALOG10(ABS(Y1)+1.E-25)	! LOG Y
			CALL PLOT(X1,Y1,NORG)
			IF (NOPT1.EQ.0) CALL PLOT(X1,Y1,2)	! POINT ONLY
			IF (MOD(NOPT1,2).EQ.1) NORG=2		! FOR LINE
			IF (NOPT1.GT.3) CALL PLOT(X1,0.,2)! FOR VERTICAL LINE TO X AXIS
			NPCNT=NPCNT+1
			IF (NPCNT.GT.NSYM) THEN
				NPCNT=1
				IF (NOPT1.EQ.2.OR.NOPT1.EQ.3.OR.
     $				    NOPT1.EQ.6) THEN
					IF (NT.LT.0.) CALL 
     $					   PLOT(FLOAT(ICOL(6+2*IN)),0.,0)!PEN COLOR
  					CALL SYMBOL(X1,Y1,AS,IN,0.,1,-1)
				ENDIF
				IF (NOPT2.GT.0) THEN
				  IF (NT.LT.0.) CALL 
     $				     PLOT(FLOAT(ICOL(6+2*IN)),0.,0)!PEN COLOR
				  Y2=(Y(II,IN+1)-YM)/DY
				  IF (IKY.LT.0) Y2=ALOG10(ABS(Y2)+1.E-25)
				  Y3=(Y(II,IN+2)-YM)/DY
				  IF (IKY.LT.0) Y3=ALOG10(ABS(Y3)+1.E-25)
				  IF (NOPT2.EQ.1) THEN
				  	CALL PLOT(X1-AS/2.,Y2,3)
				  	CALL PLOT(X1+AS/2.,Y2,2)
				  ENDIF
				  CALL PLOT(X1,Y2,3)
				  CALL PLOT(X1,Y3,2)
				  IF (NOPT2.EQ.1) THEN
					CALL PLOT(X1-AS/2.,Y3,3)
					CALL PLOT(X1+AS/2.,Y3,2)
				  ENDIF
				ENDIF
			ENDIF
			IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6+2*IN-1)),0.,0)!PEN COLOR
			CALL PLOT(X1,Y1,3)
78	CONTINUE
	CS=.21						!TITLE CHARACTER SIZE
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6)),0.,0)	!PEN COLOR
	IF (NT.NE.0.AND.JF.NE.0) THEN			!TITLE
		XP=0.0
		YP=0.0
		CALL SYMBOL(XP,YP,CS,TITLE,
     $			0.,IABS(NT),-3)			!TITLE LENGTH
		XP=ABS(XAXL/2.)-XP/2.
		IF (XP.LT.0.) XP=0.
		CALL SYMBOL(XP,ABS(YAXL)+.15,CS,TITLE,
     $			0.,IABS(NT),-1)			!PLOT TITLE
	ENDIF
	CALL PLOT(0.,0.,3)
	IF (IFLAG.GT.0) THEN
		CALL CTERM(2)				!ASK IF CLEAR SCREN
		CALL PLOTND				!CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
	ENDIF
	IF (IFLAG.LT.0) THEN
		REPEAT=.TRUE.
		CALL CTERM(1)				!RETURN TO TEXT MODE
	ENDIF
	RETURN
	END
C
C *************************************************************************
C
	SUBROUTINE GLPLOT(X,Y,NND,NPD,NN,NP,IFLAG,NSYM,XAXL,YAXL,
     1		XT,XC,XF,XTITL,NXT,YT,YC,YF,YTITL,NYT,TITLE,NT,
     2		XMIN,XMAX,YMIN,YMAX,ICOL,ILINE)
C
C	CREATED BY D. LONG       FEB, 1984	AT JPL
C
C	ROUTINE TO PLOT SEVERAL LINES OF DATA IN LOG/LINEAR COMBINATION
C	AXIS FLEXIBILITY IS PROVIDED
C
C	X	REAL X VALUE ARRAY
C	Y	REAL Y DATA ARRAY DIMENSION Y(NPD,NND)
C	NND	INT  DIMENSION OF Y
C	NPD	INT  DIMENSION OF Y
C	NN	INT  # NUMBER OF LINES TO PLOT
C	NP	INT  # OF POINTS IN IN LINE
C	IFLAG	INT
C	  (MAG) >10000 REPEAT PLOTTING BUT DO NOT INTIALIZE PLOTTER
C		< 0  REPEAT PLOTTING (DON'T CLOSE PLOTTER OUTPUT)
C		= 0  CLOSE PLOTTER OUTPUT--DO NOT PRODUCE PLOT
C		> 0  SINGLE PLOT OUTPUT ONLY (PLOTTER OUTPUT CLOSED)
C	  (ONE'S DIGIT) = 1 X LINEAR, Y LOGRITHMIC (BASE 10)
C	  (ONE'S DIGIT) = 2 X LOGRITHMIC,Y LINEAR
C	  (ONE'S DIGIT) = 3 X LOGRITHMIC,Y LOGRITHMIC
C	  (ONE'S DIGIT) = 4 X LINEAR, Y LINEAR
C	  (TEN'S DIGIT) = 0 NO AXIS OR GRID 
C	  (TEN'S DIGIT) = 1 PLOT BOX WITH AXIS TICKS
C	  (TEN'S DIGIT) = 2 PLOT SOLID GRID
C	  (TEN'S DIGIT) = 3 PLOT TICKED GRID W/O BOX
C	  (TEN'S DIGIT) = 4 PLOT TICKED GRID WITH BOX
C	  (TEN'S DIGIT) = 5 PLOT BOX WITH AXIS TICKS AND TICKED GRID
C	  (TEN'S DIGIT) = 6 PLOT W/O BOX OR GRID BUT USE AXISES
C	  (TEN'S DIGIT) = 7 PLOT SOLID LOGRITHMIC GRID
C	  (TEN'S DIGIT) = 8 PLOT DOTTED LOGRITHMIC GRID
C	  (TEN'S DIGIT) = 9 PLOT TICKED LOGRITHMIC GRID
C     (HUNDRED'S DIGIT) = 0 ASK WHICH SCREEN DEVICE TO USE
C			<>0 SCREEN DEVICE NUMBER CODE
C	NSYM	INT   NUMBER OF POINTS BETWEEN SYMBOLS
C		      < 0  SYMBOLS ONLY, NO LINE
C		      = 0  NO SYMBOLS, LINE ONLY
C		      > 0 NUMBER OF POINTS BETWEEN SYMBOLS
C	XAXL	REAL  X AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C	YAXL	REAL  Y AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C
C NOTE: 	XMIN,XMAX,YMIN,YMAX ARE ONLY REQUIRED IF XAXL OR YAXL < 0
C
C	XT,XC,XF	PARAMETERS FOR X AXIS (SEE AXIS3)
C	YT,YC,YF	PARAMETERS FOR Y AXIS (SEE AXIS3)
C	XTITL	CHAR  X AXIS TITLE
C	NXT	INT   NUMBER OF CHARACTERS IN X AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	YTITL	CHAR  Y AXIS TITLE
C	NYT	INT   NUMBER OF CHARACTERS IN Y AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	TITLE	CHAR  PLOT TITLE
C	NT	INT   NUMBER OF CHARACTERS IN PLOT TITLE
C		= 0  NO TITLE
C		< 0  USE COLOR ARRAY
C			(REQUIRES XMIN,XMAX,YMIN,YMAX BE PRESENT)
C			IF IABS(NT)/100)>1 USE LINE TYPE ARRAY
C	XMIN	REAL  MINIMUM VALUE DISPLAYED ON X AXIS
C	XMAX	REAL  MAXIMUM VALUE DISPLAYED ON X AXIS
C	YMIN	REAL  MINIMUM VALUE OF Y ARRAY
C	YMAX	REAL  MAXIMUM VALUE OF Y ARRAY
C	ICOL	INT   ARRAY OF PEN COLORS PEN DIMENSIONED ICOL(5+NN)
C			ICOL(1) = GRID COLOR
C			ICOL(2) = AXIS LINE COLOR
C			ICOL(3) = AXIS NUMBERS COLOR
C			ICOL(4) = AXIS TITLE COLOR
C			ICOL(5) = AXIS EXPONENT COLOR
C			ICOL(6) = TITLE COLOR (COLOR UPON RETURN)
C			ICOL(7) = LINE COLOR 1
C			ICOL(8) = LINE COLOR 2
C			   .	     .	     3
C	ILINE	INT  LINE TYPE ARRAY DIMENSIONED ILINE(NN)
C
	INTEGER XTITL(1),YTITL(1),TITLE(1)
	REAL Y(NPD,NND),X(NPD),PY(2)
	LOGICAL REPEAT
	INTEGER PL,ICOL(1),IC(4),ILINE(1)
	COMMON /CGLPLOT/XM,DX,YM,DY
	DATA REPEAT/.FALSE./
	PL=3					! PRINTER DATA FILE= FOR003.DAT
	IF (IFLAG.EQ.0) THEN
		IF (REPEAT) CALL PLOTND !CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
		RETURN
	ENDIF
	JF=IABS(IFLAG)
	IF (.NOT.REPEAT.AND.JF.LT.10000) THEN
		ILU=-(JF/100)			! SCREEN DEVICE, CLEAR SCREEN
		CALL FRAME(PL,ILU,1.5,1.5,1.)	! INTIALIZE PLOT PACKAGE
	ELSE
		CALL CTERM(-1)			! RESTORE PLOT MODE
C		CALL NEWPAGE			! NEW PAGE
		JF=MOD(JF,100)
	ENDIF
	JF=MOD(JF,100)
	IF=JF
	IF (IF.GT.10) IF=MOD(IF,10)
	JF=JF-IF
	NX=ABS(ANINT(XAXL))				! GRID SIZES
	NY=ABS(ANINT(YAXL))
	IF (XAXL.GT.0.0) THEN				! INPUT SCALING
	    XM=X(1)
	    DX=X(1)
	    DO 5 I=2,NP
		DX=MAX(X(I),DX)
		XM=MIN(X(I),XM)
 5	    CONTINUE
	    PY(1)=XM
	    PY(2)=DX
	    IF (IF.EQ.2.OR.IF.EQ.3) THEN
		CALL SCALG(PY,ABS(XAXL),2,1,1,XM,DX)	!SMOOTH SCALE FACTORS
		IK=-1
		GDX=1./DX
		NX=DX*ABS(XAXL)
		INX=-1
	    ELSE
		CALL SCALE(PY,ABS(XAXL),2,1,1,XM,DX)	!SMOOTH SCALE FACTORS
		IK=0
		GDX=1.
		INX=1
	    ENDIF
	ELSE
	    IF (IF.EQ.2.OR.IF.EQ.3) THEN
		XM=(ABS(XMIN)+1.E-25)
		IF (XM.NE.AINT(XM)) XM=AINT(XM)-1.
		DX=AINT(ALOG10(ABS(XMAX)+1.E-25))+1.
		DX=(DX-XM)/ABS(XAXL)
		GDX=1./DX
		IK=-1
		NX=DX*ABS(XAXL)
		INX=-1
	    ELSE
		XM=XMIN
		DX=(XMAX-XMIN)/ABS(XAXL)
		GDX=1.
		IK=0
		INX=1
	    ENDIF
	ENDIF
	IF (YAXL.GT.0.0) THEN				!INPUT SCALING
	    YM=Y(1,1)
	    DY=Y(1,1)
	    DO 6 IN=1,NN
		DO 6 I=1,NP
		    YM=MIN(Y(I,IN),YM)
		    DY=MAX(Y(I,IN),DY)
6		CONTINUE
	    PY(1)=YM
	    PY(2)=DY
	    IF (IF.EQ.1.OR.IF.EQ.3) THEN
		CALL SCALG(PY,ABS(YAXL),2,1,1,YM,DY)	!SMOOTH SCALE FACTORS
		IK=-1+IK
		GDY=1./DY
		NY=DY*ABS(YAXL)
		INY=-1
	    ELSE
		CALL SCALE(PY,ABS(YAXL),2,1,1,YM,DY)	!SMOOTH SCALE FACTORS
		IK=1+IK
		GDY=1.
		INY=1
	    ENDIF
	ELSE
	    IF (IF.EQ.1.OR.IF.EQ.3) THEN
		YM=ALOG10(ABS(YMIN)+1.E-25)
		IF (YM.NE.AINT(YM)) YM=AINT(YM)-1.
		DY=AINT(ALOG10(ABS(YMAX)+1.E-25))+1.
		DY=(DY-YM)/ABS(YAXL)
		GDY=1./DY
		NY=DY*ABS(YAXL)
		IK=-1+IK
		INY=-1
	    ELSE
		YM=YMIN
		DY=(YMAX-YMIN)/ABS(YAXL)
		IK=1+IK
		GDY=1.
		INY=1
	    ENDIF
	ENDIF
	IF (JF.EQ.0) GOTO 77		! NO AXIS OR GRID
	IF (JF.EQ.60) GOTO 76		! NO GRID
	IF (JF.GT.60) THEN		! LOGRITHMIC GRID
		II=0
		IF (JF.EQ.70) II=1
		IF (JF.EQ.80) II=2
		CALL LGRID(0.,0.,GDX,GDY,INX*NX,INY*NY,II)
		GOTO 76
	ENDIF
	IF (JF.GE.20) THEN		! CARTESIAN GRID
		IF (JF.GE.30) NX=-NX
		IF (JF.GE.40) NY=-NY
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(1)),0.,0) !PEN COLOR
		CALL GRID(0.,0.,GDX,GDY,NX,NY)		! PRODUCE GRID
		IF (JF.EQ.50) JF=10
	ENDIF
76	NADD=0
	IF (NT.LT.0) THEN
		NADD=100000		!PEN COLOR
		IC(1)=ICOL(2)
		IC(2)=ICOL(3)
		IC(3)=ICOL(4)
		IC(4)=ICOL(5)
	ENDIF
	IX=IABS(NXT)+NADD
	XL=ABS(XAXL)*ISIGN(1,NXT)		! AXIS LENGTH WITH TICK INFOR
	IF (NXT.NE.0) THEN
		IF (IF.EQ.2.OR.IF.EQ.3) THEN
		CALL LGAXS(0.,0.,XTITL,-NADD-IX,ABS(XL),0.,XM,DX,IC) ! X-AXIS
		IF (JF.EQ.10) CALL LGAXS(0.,ABS(YAXL),XTITL,IX+100+NADD,
     $			ABS(XL),0.,XM,DX,IC) ! X-AXIS TICKS
		ELSE
		CALL AXIS3(0.,0.,XTITL,-NADD-IX,XL,0.,XM,DX*ABS(XL)+XM,
     $			XT,XC,XF,IC)  ! X-AXIS
	IF (JF.EQ.10) CALL AXIS3(0.,ABS(YAXL),XTITL,-IX-100-NADD,
     $			-XL,0.,XM,DX*ABS(XL)+XM,XT,XC,XF,IC)  ! X-AXIS TICKS
		ENDIF
	ENDIF
	IY=IABS(NYT)+1000+NADD
	YL=ABS(YAXL)*ISIGN(1,NYT)
	IF (NYT.NE.0) THEN
		IF (IF.EQ.1.OR.IF.EQ.3) THEN
		CALL LGAXS(0.,0.,YTITL,NADD+IY,ABS(YL),90.,YM,DY,IC) ! Y-AXIS
		IF (JF.EQ.10) CALL LGAXS(ABS(XAXL),0.,YTITL,
     $			-IY-100-NADD,
     $			ABS(YL),90.,YM,DY,IC) ! Y-AXIS
		ELSE
		CALL AXIS3(0.,0.,YTITL,NADD+IY,YL,90.,YM,
     $			DY*ABS(YL)+YM,YT,YC,YF,IC)  		! Y-AXIS
		IF (JF.EQ.10) CALL AXIS3(ABS(XAXL),0.,YTITL,
     $			-IY-100-NADD,
     $			YL,90.,YM,DY*ABS(YL)+YM,YT,YC,YF,IC)  ! Y-AXIS
		ENDIF
	ENDIF
77	IF (IK.EQ.1) THEN
	    DO 78 IN=1,NN
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6+IN)),0.,0)!PEN COLOR
		IF (IABS(NT)/100.GT.0) CALL NEWPEN(ILINE(IN)) !LINE TYPE
	       CALL LINE(X,Y(1,IN),NP,1,NSYM,IN-1,1,1,XM,DX,YM,DY) ! PLOT DATA
78	    CONTINUE
	ELSE
	    IF (IK.EQ.-1) IK=1				    ! CORRECT FLAG
	    IF (IK.EQ.0) IK=-1
	    DO 79 IN=1,NN
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6+IN)),0.,0)!PEN COLOR
		IF (IABS(NT)/100.GT.0) CALL NEWPEN(ILINE(IN)) !LINE TYPE
		CALL LGLIN(X,Y(1,IN),NP,1,NSYM,IN-1,IK,1,1,XM,DX,YM,DY)	  !PLOT DATA
79	    CONTINUE
	ENDIF
	IF (IABS(NT)/100.GT.0) CALL NEWPEN(0)		! RESET LINE TYPE
	CS=MAX(ABS(XC),ABS(YC))				! TITLE CHARACTER SIZE
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6)),0.,0)	! PEN COLOR
	IF (NT.NE.0.AND.JF.NE.0) THEN			! TITLE
		XP=0.0
		YP=0.0
		CALL SYMBOL(XP,YP,CS,TITLE,
     $			0.,MOD(IABS(NT),100),-3)	! TITLE LENGTH
		XP=ABS(XAXL/2.)-XP/2.
		IF (XP.LT.0.) XP=0.
		CALL SYMBOL(XP,ABS(YL)+.15,CS,TITLE,
     $			0.,MOD(IABS(NT),100),-1)	! PLOT TITLE
	ENDIF
	CALL PLOT(0.,0.,3)
	IF (IFLAG.GT.0) THEN
		CALL CTERM(2)				! ASK IF CLEAR SCREN
		CALL PLOTND				! CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
	ENDIF
	IF (IFLAG.LT.0) THEN
		REPEAT=.TRUE.
		CALL CTERM(1)				! RETURN TO TEXT MODE
	ENDIF
	RETURN
	END
C
C *************************************************************************
C
	SUBROUTINE SEISPL(X,Y,Z,NND,NPD,NN,NP,IFLAG,NTYPE,SIZE,ZERO,
     1			XAXL,YAXL,XTITL,NXT,YTITL,NYT,TITLE,NT,
     2			XMIN,XMAX,YMIN,YMAX,ICOL)
C
C	CREATED BY D. LONG       APR, 1985	AT JPL
C
C	ROUTINE TO PLOT IN THE STYLES OFTEN USED IN SEISMIC PROCESSING
C
C	X	REAL X DATA ARRAY DIMENSION X(NPD)
C	Y	REAL Y DATA ARRAY DIMENSION Y(NPD,NND)
C	Z	REAL OFFSET VALUE ARRAY DIMENSION Z(NN)
C			OFFSET VALUE IS ADDED TO Y VALUE BEFORE PLOTTING.
C			WHEN USING LOG SCALING NOTE THAT THIS OCCURS AFTER
C			TAKING LOG OF DATA.  THIS ARRAY IS USED FOR VERTICALLY
C			OFFSETTING DIFFERENT PLOTTED LINES.
C	NND	INT  DIMENSION OF Y ARRAY
C	NPD	INT  DIMENSION OF X,Y ARRAYS
C	NN	INT  NUMBER OF LINES ARRAYS
C	NP	INT  NUMBER OF POINTS TO PLOT
C	IFLAG	INT
C	  (MAG) >10000 REPEAT PLOTTING BUT DO NOT INTIALIZE PLOTTER
C		< 0  REPEAT PLOTTING (DON'T CLOSE PLOTTER OUTPUT)
C		= 0  CLOSE PLOTTER OUTPUT--DO NOT PRODUCE PLOT
C		> 0  SINGLE PLOT OUTPUT ONLY (PLOTTER OUTPUT CLOSED)
C	  (ONE'S DIGIT) = 1 X LINEAR, Y LOGRITHMIC (BASE 10)
C	  (ONE'S DIGIT) = 2 X LOGRITHMIC,Y LINEAR
C	  (ONE'S DIGIT) = 3 X LOGRITHMIC,Y LOGRITHMIC
C	  (ONE'S DIGIT) = 4 X LINEAR, Y LINEAR
C	  (TEN'S DIGIT) = 0 NO AXIS OR GRID 
C	  (TEN'S DIGIT) = 1 PLOT BOX WITH AXIS TICKS
C	  (TEN'S DIGIT) = 2 PLOT SOLID GRID
C	  (TEN'S DIGIT) = 3 PLOT TICKED GRID W/O BOX
C	  (TEN'S DIGIT) = 4 PLOT TICKED GRID WITH BOX
C	  (TEN'S DIGIT) = 5 PLOT BOX WITH AXIS TICKS AND TICKED GRID
C	  (TEN'S DIGIT) = 6 PLOT W/O BOX OR GRID BUT USE AXISES
C	  (TEN'S DIGIT) = 7 PLOT SOLID LOGRITHMIC GRID
C	  (TEN'S DIGIT) = 8 PLOT DOTTED LOGRITHMIC GRID
C	  (TEN'S DIGIT) = 9 PLOT TICKED LOGRITHMIC GRID
C     (HUNDRED'S DIGIT) = 0 ASK WHICH SCREEN DEVICE TO USE
C		      <>0 SCREEN DEVICE CODE NUMBER
C	NTYPE	INT   PLOTTING TYPE CODE
C			< 0 ZERO REFERENCE PLOTTED
C	   MAG(NTYPE)	= 0 SYMBOLS ONLY
C			= 1 SYMBOLS ONLY
C			= 2 POINTS ONLY
C			= 3 CONNECTED POINTS
C			= 4 VERTICAL LINES FROM POINTS TO CENTER LINE
C			= 5 VERTICAL LINES PLUS SYMBOL
C			= 6 CONNECTED POINTS WITH VERTICAL LINES
C			= 7 CONNECTED POINTS WITH VERTICAL LINES ON POSITIVE HALF
C			= 8 CONNECTED POINTS WITH VERTICAL LINES ON NEGATIVE HALF
C			= 9 AREA BETWEEN CONNECTED POINTS AND ZERO FILLED
C			= 10 POSITIVE AREA BETWEEN POINTS AND ZERO FILLED
C			= 11 NEGATIVE AREA BETWEEN POINTS AND ZERO FILLED
C	SIZE	REAL  PLOTTED SYMBOL SCALE (NTYPE = 0,1, OR 4)
C		      SPACING BETWEEN SOLID FILL LINES (NTYPE = 9,10,11)
C		      SIZE < 0.0 WILL MAKE CENTER LINE DOTTED
C	ZERO	REAL  VALUE USED AS PLOT ZERO
C	XAXL	REAL  X AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C	YAXL	REAL  Y AXIS LENGTH IN INCHES
C		< 0  USE INPUT VALUE SCALING--AXIS PLOTTED
C		> 0  USE AUTO SCALING--AXIS PLOTTED
C
C NOTE: 	XMIN,XMAX,YMIN,YMAX ARE ONLY REQUIRED IF XAXL OR YAXL < 0
C
C	XTITL	CHAR  X AXIS TITLE
C	NXT	INT   NUMBER OF CHARACTERS IN X AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	YTITL	CHAR  Y AXIS TITLE
C	NYT	INT   NUMBER OF CHARACTERS IN Y AXIS TITLE STRING
C		< 0  TICKS ON INSIDE OF AXIS
C		= 0  NO AXIS
C		> 0  TICKS ON TITLE SIDE OF AXIS
C	TITLE	CHAR  PLOT TITLE
C	NT	INT   NUMBER OF CHARACTERS IN PLOT TITLE
C		= 0  NO TITLE
C		< 0  USE COLOR ARRAY (REQUIRES XMIN,XMAX,YMIN,YMAX TOO)
C	XMIN	REAL  MINIMUM VALUE DISPLAYED ON X AXIS
C	XMAX	REAL  MAXIMUM VALUE DISPLAYED ON X AXIS
C	YMIN	REAL  MINIMUM VALUE OF Y ARRAY
C	YMAX	REAL  MAXIMUM VALUE OF Y ARRAY
C	ICOL	INT   ARRAY OF PEN COLORS DIMENSIONED ICOL(NP+6)
C			ICOL(1) = GRID COLOR
C			ICOL(2) = AXIS LINE COLOR
C			ICOL(3) = AXIS NUMBERS COLOR
C			ICOL(4) = AXIS TITLE COLOR
C			ICOL(5) = AXIS EXPONENT COLOR
C			ICOL(6) = TITLE COLOR (COLOR UPON RETURN)
C			ICOL(7) = POINT SET COLOR 1
C			ICOL(8) = POINT SET COLOR 2
C			   .	     .	          3
C
	INTEGER XTITL(1),YTITL(1),TITLE(1)
	REAL Y(NPD,NND),X(NPD),Z(NND),PY(2)
	LOGICAL REPEAT
	INTEGER PL,ICOL(1),IC(4)
	COMMON /CSEISPL/XM,DX,YM,DY
	DATA REPEAT/.FALSE./
	CS=.21						! TITLE CHARACTER SIZE
C
C	HANDLE PLOT PACKAGE INITIALIZATION
C
	PL=3				!DEFAULT PRINTER DATA FILE= FOR003.DAT
	IF (IFLAG.EQ.0) THEN
		IF (REPEAT) CALL PLOTND !CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
		RETURN
	ENDIF
	JF=IABS(IFLAG)
	IF (.NOT.REPEAT.AND.JF.LT.10000) THEN
		ILU=-(JF/100)				!SCREEN DEVICE, CLEAR SCREEN
		CALL FRAME(PL,ILU,1.2,1.2,1.)		!INTIALIZE PLOT PACKAGE
	ELSE
		CALL CTERM(-1)				!RESTORE PLOT MODE
C		CALL NEWPAGE				!NEW PAGE
		JF=MOD(JF,100)
	ENDIF
	JF=MOD(JF,100)
	IF=JF
	IF (IF.GT.10) IF=MOD(IF,10)
	JF=JF-IF
	NX=ABS(ANINT(XAXL))				!GRID SIZES
	NY=ABS(ANINT(YAXL))
C
C	DETERMINE SCALING PARAMETERS
C
	IF (XAXL.GT.0.0) THEN				!INPUT SCALING
	    XM=X(1)
	    DX=X(1)
	    DO 4 I=2,NP
		XM=MAX(X(I),XM)
		DX=MIN(X(I),DX)
   4	    CONTINUE
	    PY(1)=XM
	    PY(2)=DX
	    IF (IF.EQ.2.OR.IF.EQ.3) THEN
		CALL SCALG(PY,ABS(XAXL),2,1,1,XM,DX)	!SMOOTH SCALE FACTORS
		IK=-1
		GDX=1./DX
		NX=DX*ABS(XAXL)
		INX=-1
	    ELSE
		CALL SCALE(PY,ABS(XAXL),2,1,1,XM,DX)	!SMOOTH SCALE FACTORS
		IK=0
		GDX=1.
		INX=1
	    ENDIF
	ELSE
	    IF (IF.EQ.2.OR.IF.EQ.3) THEN
		XM=(ABS(XMIN)+1.E-25)
		IF (XM.NE.AINT(XM)) XM=AINT(XM)-1.
		DX=AINT(ALOG10(ABS(XMAX)+1.E-25))+1.
		DX=(DX-XM)/ABS(XAXL)
		GDX=1./DX
		IK=-1
		NX=DX*ABS(XAXL)
		INX=-1
	    ELSE
		XM=XMIN
		DX=(XMAX-XMIN)/ABS(XAXL)
		GDX=1.
		IK=0
		INX=1
	    ENDIF
	ENDIF
	IF (YAXL.GT.0.0) THEN				!INPUT SCALING
	    YM=Y(1,1)
	    DY=Y(1,1)
	    DO 5 N=1,NN
		DO 5 I=1,NP
		    YM=MAX(Y(I,N)+Z(N),YM)
		    DY=MIN(Y(I,N)+Z(N),DY)
5	    CONTINUE
	    PY(1)=YM
	    PY(2)=DY
	    IF (IF.EQ.1.OR.IF.EQ.3) THEN
		CALL SCALG(PY,ABS(YAXL),2,1,1,YM,DY)	!SMOOTH SCALE FACTORS
		IK=-1+IK
		GDY=1./DY
		NY=DY*ABS(YAXL)
		INY=-1
	    ELSE
		CALL SCALE(PY,ABS(YAXL),2,1,1,YM,DY)	!SMOOTH SCALE FACTORS
		IK=1+IK
		GDY=1.
		INY=1
	    ENDIF
	ELSE
	    IF (IF.EQ.1.OR.IF.EQ.3) THEN
		YM=ALOG10(ABS(YMIN)+1.E-25)
		IF (YM.NE.AINT(YM)) YM=AINT(YM)-1.
		DY=AINT(ALOG10(ABS(YMAX)+1.E-25))+1.
		DY=(DY-YM)/ABS(YAXL)
		GDY=1./DY
		NY=DY*ABS(YAXL)
		IK=-1+IK
		INY=-1
	    ELSE
		YM=YMIN
		DY=(YMAX-YMIN)/ABS(YAXL)
		IK=1+IK
		GDY=1.
		INY=1
	    ENDIF
	ENDIF
	IF (JF.EQ.0) GOTO 77				!NO AXIS OR GRID
C
C	PLOT GRID
C
	IF (JF.EQ.60) GOTO 76				!NO GRID
	IF (JF.GT.60) THEN				!LOGRITHMIC GRID
		II=0
		IF (JF.EQ.70) II=1
		IF (JF.EQ.80) II=2
		CALL LGRID(0.,0.,GDX,GDY,INX*NX,INY*NY,II)
		GOTO 76
	ENDIF
	IF (JF.GE.20) THEN				!CARTESIAN GRID
		IF (JF.GE.30) NX=-NX
		IF (JF.GE.40) NY=-NY
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(1)),0.,0) ! PEN COLOR
		CALL GRID(0.,0.,GDX,GDY,NX,NY)		!PRODUCE GRID
		IF (JF.EQ.50) JF=10
	ENDIF
76	NADD=0
C
C	PLOT AXES
C
	IF (NT.LT.0) THEN
		NADD=100000				!PEN COLOR
		IC(1)=ICOL(2)
		IC(2)=ICOL(3)
		IC(3)=ICOL(4)
		IC(4)=ICOL(5)
	ENDIF
	IX=IABS(NXT)
	XL=ABS(XAXL)*SIGN(1.,FLOAT(NXT))		!AXIS LENGTH WITH TICK INFOR
	IF (NXT.NE.0) THEN
		IF (IF.EQ.2.OR.IF.EQ.3) THEN
		CALL LGAXS(0.,0.,XTITL,-IX-NADD,XL,0.,XM,DX,IC) !X-AXIS
		IF (JF.EQ.10) CALL LGAXS(0.,ABS(YAXL),XTITL,IX+100+NADD,
     $			XL,0.,XM,DX,IC) 		!X-AXIS
		ELSE
		CALL AXIS(0.,0.,XTITL,-IX-NADD,XL,0.,XM,DX,N1,N2,IC)  !X-AXIS
		IF (JF.EQ.10) CALL AXIS(0.,ABS(YAXL),XTITL,IX+100+NADD,
     $			XL,0.,XM,DX,N1,N2,IC)  		!X-AXIS
		ENDIF
	ENDIF
	IY=IABS(NYT)+1000
	YL=ABS(YAXL)*SIGN(1.,FLOAT(NYT))
	IF (NYT.NE.0) THEN
		IF (IF.EQ.1.OR.IF.EQ.3) THEN
		CALL LGAXS(0.,0.,YTITL,IY+NADD,YL,90.,YM,DY,IC) !Y-AXIS
		IF (JF.EQ.10) CALL LGAXS(ABS(XAXL),0.,YTITL,-IY-100-NADD,
     $			YL,90.,YM,DY,IC) 		!Y-AXIS
		ELSE
		CALL AXIS(0.,0.,YTITL,IY+NADD,YL,90.,YM,DY,N1,N2,IC)  !Y-AXIS
		IF (JF.EQ.10) CALL AXIS(ABS(XAXL),0.,YTITL,-IY-100-NADD,
     $			YL,90.,YM,DY,N1,N2,IC)		!Y-AXIS
		ENDIF
	ENDIF
77	CONTINUE
C
C	NOW PLOT DATA
C
	RES=ABS(SIZE)
	NTP=IABS(NTYPE)
	DO 79 IN=1,NN
		IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6+IN)),0.,0)   !PEN COLOR
		Z1=ZERO+Z(IN)
		IF (IF.EQ.1.OR.IF.EQ.3) Z1=ALOG10(ABS(Z1)+1.E-25)
		Z1=(Z1-YM)/DY
		IP=3
		DO 79 I=1,NP
		    X1=X(I)
		    IF (IF.EQ.2.OR.IF.EQ.3) X1=ALOG10(ABS(X1)+1.E-25)
		    Y1=Y(I,IN)+Z(IN)
		    IF (IF.EQ.1.OR.IF.EQ.3) Y1=ALOG10(ABS(Y1)+1.E-25)
		    X1=(X1-XM)/DX
		    Y1=(Y1-YM)/DY
		    IF (I.EQ.1) XOLD=X1
		    IF (I.EQ.1) YOLD=Y1
		    IF (NTP.EQ.0.OR.NTP.EQ.1) THEN	! SYMBOLS ONLY
			CALL SYMBOL(X1,Y1,ABS(SIZE),IN,0.,1,-1)
			IF (NTYPE.LT.0) THEN	! ADD CENTER LINE
				IF (SIZE.LT.0.0) CALL NEWPEN(1)
				CALL PLOT(XOLD,Z1,3)
				CALL PLOT(X1,Z1,2)
				IF (SIZE.LT.0.0) CALL NEWPEN(0)
			ENDIF
		    ENDIF
		    IF (NTP.EQ.2) THEN		! DOTS ONLY
			CALL PLOT(X1,Y1,3)
			CALL PLOT(X1,Y1,2)
			IF (NTYPE.LT.0) THEN	! ADD CENTER LINE
				IF (SIZE.LT.0.0) CALL NEWPEN(1)
				CALL PLOT(XOLD,Z1,3)
				CALL PLOT(X1,Z1,2)
				IF (SIZE.LT.0.0) CALL NEWPEN(0)
			ENDIF
		    ENDIF
		    IF (NTP.EQ.3) THEN		! CONNECTED POINTS
			IF (NTYPE.LT.0) CALL PLOT(XOLD,YOLD,3)
			CALL PLOT(X1,Y1,IP)
			IF (NTYPE.LT.0) THEN	! ADD CENTER LINE
				IF (SIZE.LT.0.0) CALL NEWPEN(1)
				CALL PLOT(XOLD,Z1,3)
				CALL PLOT(X1,Z1,2)
				IF (SIZE.LT.0.0) CALL NEWPEN(0)
			ENDIF
		    ENDIF
		    IF (NTP.EQ.4) THEN		! VERTICAL LINES ONLY
			CALL PLOT(X1,Y1,3)
			CALL PLOT(X1,Z1,2)
			IF (NTYPE.LT.0) THEN	! ADD CENTER LINE
				IF (SIZE.LT.0.0) CALL NEWPEN(1)
				CALL PLOT(X1,Z1,3)
				CALL PLOT(XOLD,Z1,2)
				IF (SIZE.LT.0.0) CALL NEWPEN(0)
			ENDIF
		    ENDIF
		    IF (NTP.EQ.5) THEN		! VERTICAL LINES PLUS SYMBOL
			CALL SYMBOL(X1,Y1,ABS(SIZE),IN,0.,1,-1)
			CALL PLOT(X1,Z1,2)
			IF (NTYPE.LT.0) THEN	! ADD CENTER LINE
				IF (SIZE.LT.0.0) CALL NEWPEN(1)
				CALL PLOT(X1,Z1,3)
				CALL PLOT(XOLD,Z1,2)
				IF (SIZE.LT.0.0) CALL NEWPEN(0)
			ENDIF
		    ENDIF
		    IF (NTP.EQ.6) THEN		! CONNECTED LINES
			CALL PLOT(X1,Y1,IP)
			CALL PLOT(X1,Z1,2)
			IF (NTYPE.LT.0) THEN	! ADD CENTER LINE
				IF (SIZE.LT.0.0) CALL NEWPEN(1)
				CALL PLOT(X1,Z1,3)
				CALL PLOT(XOLD,Z1,2)
				IF (SIZE.LT.0.0) CALL NEWPEN(0)
			ENDIF
			CALL PLOT(X1,Y1,3)
		    ENDIF
		    IF (NTP.EQ.7) THEN		! POSITIVE HALF CONNECTED LINES
			CALL PLOT(X1,Y1,IP)
			IF (Y1.GT.Z1) THEN
				CALL PLOT(X1,Z1,2)
				CALL PLOT(X1,Y1,2)
			ENDIF
			IF (NTYPE.LT.0) THEN	! ADD CENTER LINE
				IF (SIZE.LT.0.0) CALL NEWPEN(1)
				CALL PLOT(XOLD,Z1,3)
				CALL PLOT(X1,Z1,2)
				IF (SIZE.LT.0.0) CALL NEWPEN(0)
				CALL PLOT(X1,Y1,3)
			ENDIF
		    ENDIF
		    IF (NTP.EQ.8) THEN		! NEGATIVE HALF CONNECTED LINES
			CALL PLOT(X1,Y1,IP)
			IF (Y1.LT.Z1) THEN
				CALL PLOT(X1,Z1,2)
				CALL PLOT(X1,Y1,2)
			ENDIF
			IF (NTYPE.LT.0) THEN	! ADD CENTER LINE
				IF (SIZE.LT.0.0) CALL NEWPEN(1)
				CALL PLOT(XOLD,Z1,3)
				CALL PLOT(X1,Z1,2)
				IF (SIZE.LT.0.0) CALL NEWPEN(0)
				CALL PLOT(X1,Y1,3)
			ENDIF
		    ENDIF
		    IF (NTP.EQ.9) THEN		! FILLED AREA
			CALL PLOT(XOLD,YOLD,3)
			CALL PLOT(X1,Y1,2)
			DDX=X1-XOLD
			IF (DDX.NE.0.0) THEN
			    IXX=DDX/RES
			    DDY=(Y1-YOLD)/(X1-XOLD)*RES
			    DO 80 IX=1,IXX
				X2=XOLD+IX*RES
				Y2=YOLD+IX*DDY
				CALL PLOT(X2,Z1,3)
				CALL PLOT(X2,Y2,2)
80			    CONTINUE
			ENDIF
		    ENDIF
		    IF (NTP.EQ.10) THEN		! POSITIVE HALF FILLED AREA
			CALL PLOT(XOLD,YOLD,3)
			CALL PLOT(X1,Y1,2)
			DDX=X1-XOLD
			IF (DDX.NE.0.0) THEN
			    IXX=DDX/RES
			    DDY=(Y1-YOLD)/(X1-XOLD)*RES
			    DO 82 IX=1,IXX
				X2=XOLD+IX*RES
				Y2=YOLD+IX*DDY
				IF (Y2.GT.Z1) THEN
					CALL PLOT(X2,Z1,3)
					CALL PLOT(X2,Y2,2)
				ENDIF
82			    CONTINUE
			ENDIF
			IF (NTYPE.LT.0) THEN
				IF (SIZE.LT.0.0) CALL NEWPEN(1)
				CALL PLOT(XOLD,Z1,3)
				CALL PLOT(X1,Z1,2)
				IF (SIZE.LT.0.0) CALL NEWPEN(0)
			ENDIF
		    ENDIF
		    IF (NTP.EQ.11) THEN		! POSITIVE HALF FILLED AREA
			CALL PLOT(XOLD,YOLD,3)
			CALL PLOT(X1,Y1,2)
			DDX=X1-XOLD
			IF (DDX.NE.0.0) THEN
			    IXX=DDX/RES
			    DDY=(Y1-YOLD)/(X1-XOLD)*RES
			    DO 84 IX=1,IXX
				X2=XOLD+IX*RES
				Y2=YOLD+IX*DDY
				IF (Y2.LT.Z1) THEN
					CALL PLOT(X2,Z1,3)
					CALL PLOT(X2,Y2,2)
				ENDIF
84			    CONTINUE
			ENDIF
			IF (NTYPE.LT.0) THEN
				IF (SIZE.LT.0.0) CALL NEWPEN(1)
				CALL PLOT(XOLD,Z1,3)
				CALL PLOT(X1,Z1,2)
				IF (SIZE.LT.0.0) CALL NEWPEN(0)
			ENDIF
		    ENDIF
C
		    XOLD=X1
		    YOLD=Y1
		    IP=2
 79	CONTINUE
C
C	PLOT TITLE
C
	IF (NT.LT.0) CALL PLOT(FLOAT(ICOL(6)),0.,0)	! PEN COLOR
	IF (NT.NE.0.AND.JF.NE.0) THEN			! TITLE
		XP=0.
		YP=0.
		CALL SYMBOL(XP,YP,
     $			CS,TITLE,0.,IABS(NT),-3)	! TITLE LENGTH
		XP=ABS(XAXL/2.)-XP/2.
		IF (XP.LT.0.) XP=0.
		CALL SYMBOL(XP,ABS(YAXL)+.15,
     $			CS,TITLE,0.,IABS(NT),-1)	! PLOT TITLE
	ENDIF
	CALL PLOT(0.,0.,3)
C
C	PLOT PACKAGE STUFF
C
	IF (IFLAG.GT.0) THEN
		CALL CTERM(2)				! ASK IF CLEAR SCREN
		CALL PLOTND				! CLOSE PLOT PACKAGE
		REPEAT=.FALSE.
	ENDIF
	IF (IFLAG.LT.0) THEN
		REPEAT=.TRUE.
		CALL CTERM(1)				! RETURN TO TEXT MODE
	ENDIF
	RETURN
	END
C
C *************************************************************************
C
	SUBROUTINE CNT3D(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,
     $		NLEVELS,ASTART,AEND,IDIR,IFLAG,IAXIS,
     $		XT,NXT,XASTART,XAEND,YT,NYT,ZT,NZT,ZASTART,ZAEND,
     $		AMININ,AMAXIN,ICOL,ILINE)
C
C	CREATED BY D. LONG  JULY, 1985	AT JPL
C	MODIFIED BY D. LONG   FEB, 1986 AT JPL + ADDED LINE TYPE ARRAY
C
C	SIMPLIFIES CALLING CNT3DX ROUTINE AXISES
C
	DIMENSION A(INX,INZ),ICOL(1),ILINE(1),ASTART(1)
	INTEGER XT(1),YT(1),ZT(1)
	IAX=MOD(IAXIS,10)
	IF (IAXIS.LT.0) THEN
		AMN=AMININ
		AMX=AMAXIN
	ENDIF
	IF (MOD(IABS(IFLAG),10).EQ.1) THEN
		CALL CNT3DX(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,
     $			NLEVELS,ASTART,AEND,IDIR,IFLAG,IAX,
     $			XT,NXT,XASTART,XAEND,NMX,NNX,MLX,TSX,NDX,SMX,
     $			YT,NYT,NMY,NNY,MLY,TSY,NDY,SMY,
     $			ZT,NZT,ZASTART,ZAEND,NMZ,NNZ,MLZ,TSZ,NDZ,SMZ,
     $			AMN,AMX,ICOL,IC)
	ELSE IF (MOD(IABS(IFLAG),10).GT.1) THEN
		CALL CNT3DX(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,
     $			NLEVELS,ASTART,AEND,IDIR,IFLAG,IAX,
     $			XT,NXT,XASTART,XAEND,NMX,NNX,MLX,TSX,NDX,SMX,
     $			YT,NYT,NMY,NNY,MLY,TSY,NDY,SMY,
     $			ZT,NZT,ZASTART,ZAEND,NMZ,NNZ,MLZ,TSZ,NDZ,SMZ,
     $			AMN,AMX,ICOL,ILINE)
	ELSE
		CALL CNT3DX(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,
     $			NLEVELS,ASTART,AEND,IDIR,IFLAG,IAX,
     $			XT,NXT,XASTART,XAEND,NMX,NNX,MLX,TSX,NDX,SMX,
     $			YT,NYT,NMY,NNY,MLY,TSY,NDY,SMY,
     $			ZT,NZT,ZASTART,ZAEND,NMZ,NNZ,MLZ,TSZ,NDZ,SMZ,
     $			AMN,AMX,IC)
	ENDIF
	RETURN
	END
C
C **************************************************************************
C
	SUBROUTINE CNT3DX(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,
     $		NLEVELS,ASTART,AEND,IDIR,IFLAG,IAXIS,
     $		XT,NXT,XASTART,XAEND,NMX,NNX,MLX,TSX,NDX,SMX,
     $		YT,NYT,NMY,NNY,MLY,TSY,NDY,SMY,
     $		ZT,NZT,ZASTART,ZAEND,NMZ,NNZ,MLZ,TSZ,NDZ,SMZ,
     $		AMININ,AMAXIN,ICOL,ILINE)
C
C	CREATED BY D. LONG     JULY, 1985	AT JPL
C	MODIFIED BY D. LONG   FEB, 1986 AT JPL + ADDED LINE TYPE ARRAY
C
C	ROUTINE TO PLOT DATA IN 3-D CONTOUR FORM SIMILAR TO VAX3DX
C	DOES NOT DO HIDDEN LINE REMOVAL
C
C	COORDINATE SYSTEM IS:		Y  Z
C				NAMES:	|/
C					 \X
C
C	A	(R) ARRAY A(INX,INZ) CONTAINING VERTICAL HEIGHT DATA
C	INX,INZ (I) DIMENSION OF A ARRAY
C	NX,NZ	(I) INDICATING SIZE OF A ARRAY TO PLOT
C	ALPHA	(R) ANGLE (IN DEGREES) OF X AXIS (NX) FROM HORIZONTAL
C	BETA	(R) ANGLE (IN DEGREES) OF Z AXIS (NZ) FROM HORIZONTAL
C	XH,YH,ZH(R) LENGTH OF EACH AXIS (INCHES)
C	NLEVELS REAL NUMBER OF UNIFORMLY SPACED CONTOUR LEVELS BETWEEN
C			 VALUES ASTART AND AEND.  Jth CONTOUR IS
C			 (J-1)*(AEND-ASTART)/(NL-1)+ASTART
C			IF NLEVELS < 0 THEN MIN(V) AND MAX(V) ARE USED
C			 AS ASTART AND AEND VALUES
C			IF NLEVELS = 0 THEN ASTART IS USED CONTOUR LIST 
C			 WITH INT(AEND) THE NUMBER OF CONTOURS
C	ASTART  REAL STARTING VALUE OF CONTOUR PLOT LEVELS (NLEVELS<>0)
C		     CONTOUR LIST (NLEVELS=0) DIMENSIONED ASTART(INT(AEND))
C	AEND    REAL ENDING VALUE OF CONTOUR PLOT LEVELS (NLEVELS<>0)
C		     NUMBER OF CONTOURS IN ASTART (NLEVELS=0)
C	IDIR	(I) CONTOUR EDGING FLAG
C			< 0 EXTEND CONTOUR SURFACE TO EDGES LESS THAN CONTOUR LEVEL
C			= 0 DO NOT EXTEND CONTOUR EDGES
C			> 0 EXTEND CONTOUR SURFACE TO EDGES GREATER THAN CONTOUR 
C	IFLAG	(I) PLOT FLAG
C		>10000	REPEAT PLOTTING BUT DO NOT INTIALIZE PLOTTER
C		< 0	REPEAT PLOTTING (DON'T CLOSE PLOTTER OUTPUT
C		= 0	CLOSE PLOTTER OUTPUT--DO NOT PRODUCE PLOT
C		> 0	SINGLE PLOT OUTPUT ONLY (PLOTTER OUTPUT CLOSED)
C 	(ONE'S DIGIT)	= 1 DO NOT USE PEN COLOR OR LINE TYPE ARRAY
C			= 2 USE PEN COLOR CONTROL ARRAY BUT NOT LINE TYPE
C 			= 3 DO NOT USE PEN COLOR BUT DO USE LINE TYPE
C 			= 4 USE PEN COLOR AND LINE TYPE ARRAYS
C 	(HUNDREDS'S)	= 0 ASK WHICH SCREEN DEVICE TO USE
C		   	<>0 SCREEN DEVICE CODE NUMBER
C 	IAXIS	(I) AXIS OPTION FLAG
C			= 0	DO NOT PLOT AXIS--FOLLOWING VARIABLES NOT REQUIRED
C			< 0	PLOT AXIS, USE INPUT Y AXIS SCALE--FOLLOWING VARIABLES REQUIRED
C			> 0	PLOT AXIS, USE COMPUTED Y AXIS SCALE--FOLLOWING VARIABLES REQUIRED
C 	(ONE'S DIGIT)	= 1	PLOT AXIS, Y AXIS SCALE--VARIABLES REQUIRED
C			= 2	PLOT AXIS, AUTO SCALE Y AXIS--VARIABLES REQUIRED
C	(TEN'S DIGIT)	= 0	DEFAULT AXIS PARAMETERS
C			= 1	SPECIALIZED AXIS2 PARAMETERS
C 	XT,YT,ZT	(B) STRINGS FOR AXIS TITLES
C 	NXT,NYT,NZT	(I)  LENGTH OF AXIS TITLES
C			     IF ZERO THEN THAT AXIS NOT PLOTTED
C 	XASTART,ZASTART	(R) AXIS START VALUES
C 	XAEND,ZAEND	(R) AXIS END VALUES
C FOLLOWING ONLY REQUIRED IF TEN'S DIGIT OF IFLAG=1
C	NMX,NMY,NMZ	(I) NUMBER OF MINOR TICKS BETWEEN MAJOR TICKS
C	NNX,NNY,NNZ	(I) HIGHLIGHT LENGTH OF NNX-TH MINOR TICK ON AXIS
C	MLX,MLY,MLZ	(I) NUMBER OF MAJOR TICK MARKS ON AXIS
C	TSX,TSY,TSZ	(R) SIZE OF TITLE AND NUMBERS OF AXIS
C			  IF LESS THAN ZERO DO NOT AUTO-SCALE BY (x10^POWER)
C 	NDX,NDY,NDZ	(R) NUMBER OF DIGITS TO RIGHT OF DECIMAL POINT
C 	SMX,SMY,SMZ	(R) MAJOR TICK LENGTH
C 	AMININ,AMAXIN 	(R) YAXIS SCALING FACTORS (ONLY NEEDED IF IAXIS < 0)
C	ICOL		(I) COLOR INDEX TABLE (REQUIRED IF MOD(IFLAG,10)>1)
C				ICOL(1) AXIS LINE COLOR
C				ICOL(2) AXIS NUMBERS COLOR
C				ICOL(3) AXIS TITLE COLOR
C				ICOL(4) AXIS EXPONENT COLOR
C				ICOL(5) CONTOUR LINE 1
C				ICOL(6) CONTOUR LINE 2
C				ICOL(7)   . . .      3
C				 ...      ...       ...
C	ILINE		(I) LINE TYPE ARRAY FOR CONTOURS
C				(REQUIRED IF MOD(IABS(IFLAG),10)>2)
C
	DIMENSION A(INX,INZ),PAS(2),ICOL(1),IC(4),ILINE(1),ASTART(1)
	LOGICAL REPEAT
	INTEGER XT(1),YT(1),ZT(1)
	COMMON /LOCATE/ XSCALE,YSCALE,ZSCALE,AMIN,ALPH,BET
	DATA TPI/3.141592654/,REPEAT/.FALSE./
C
	IF (IFLAG.EQ.0) THEN
		IF (REPEAT) CALL PLOTND	!CLOSE PLOTTER
		REPEAT=.FALSE.
		RETURN
	ENDIF
	ALPH=ALPHA*TPI/180.		!X-AXIS INCLINATION 0-80 DEGS
	BET=BETA*TPI/180.		!Z-AXIS ANGLE 5-80 DEGS
C
	IF (IAXIS.LT.0) THEN
		AMAX=AMAXIN
		AMIN=AMININ
	ELSE
		AMAX=A(1,1)
		AMIN=A(1,1)
		DO 16 IZ=1,NZ			!DETERMINE MAX,MIN ARRAY VALUES
			DO 16 IX=1,NX
				AMAX=AMAX1(AMAX,A(IX,IZ))
				AMIN=AMIN1(AMIN,A(IX,IZ))
16		CONTINUE
	ENDIF
	IF (ALPHA.LT.0..OR.ALPHA.GT.88..OR.BETA.LT.1..OR.BETA.GT.90.) THEN
		WRITE(*,3000)
3000		FORMAT(' *** CNT3DX INPUT ANGLE ERROR ***')
		RETURN
	ENDIF
	IF (AMAX.EQ.AMIN) THEN
		WRITE(*,3001)
3001		FORMAT(' *** CNT3DX ERROR *** MAX=MIN')
		AMAX=AMIN+1.
	ENDIF
C
	XLEN=ABS(XH)
	XSCALE=XLEN/FLOAT(NX-1)
	ZLEN=ABS(ZH)
	ZSCALE=ZLEN/FLOAT(NZ-1)
	YLEN=ABS(YH)
	IF (MOD(IABS(IAXIS),10).EQ.2) THEN
		PAS(1)=AMAX
		PAS(2)=AMIN
		CALL SCALE(PAS,YLEN,2,1,1,AMIN,DAA)
		AMAX=YLEN*DAA+AMIN
	ENDIF
	YSCALE=1.0
	IF (AMAX-AMIN.NE.0.0) YSCALE=YLEN/(AMAX-AMIN)
C
C	INTIALIZE PLOT PACKAGE
C
	JF=IABS(IFLAG)
	IF (.NOT.REPEAT.AND.JF.LT.10000) THEN
		ILU=-JF/10
		CALL FRAME(3,ILU,1.5,0.65,1.)		!INTIALIZE
	ELSE
		CALL CTERM(-1)				!PUT TERMINAL PLOT MODE
	ENDIF
C
	IAF=IABS(IAXIS)/10
	JF=MOD(JF,10)
	IF (IAXIS.NE.0) THEN		!PLOT AXIS LABELS
		NADD=0
		IF (JF.EQ.2.OR.JF.EQ.4) THEN
			IC(1)=ICOL(2)
			IC(2)=ICOL(3)
			IC(3)=ICOL(4)
			IC(4)=ICOL(5)
			NADD=100000	! PEN COLOR
		ENDIF
		CALL VXPT3D(XP,YP,AMIN,1,1,NX)
		DY=(AMAX-AMIN)/YLEN
		IF (NYT.GT.0) THEN 	!PLOT Y AXIS
			IF (IAF.EQ.1) THEN
				CALL AXIS2(XP,YP,YT,NYT+11000+NADD,
     $				YLEN,90.,AMIN,DY,NMY,NNY,-IABS(MLY),
     $				TSY,NDY,SMY,IC)
			ELSE
				CALL AXIS(XP,YP,YT,NYT+1000+NADD,
     $					YLEN,90.,AMIN,DY,N1,N2,IC)
			ENDIF
		ENDIF
		CALL VXPT3D(XP1,YP1,AMIN,NX,1,NX)
		DX=(XAEND-XASTART)/XLEN
		ANG=ATAN2(YP1-YP,XP1-XP)*180./TPI
		IF (NXT.GT.0) THEN
			IF (IAF.EQ.1) THEN
				CALL AXIS2(XP,YP,XT,-NXT-NADD-10000,XLEN,ANG,
     $				XASTART,DX,NMX,NNX,-IABS(MLX),TSX,NDX,SMX,IC)
			ELSE
				CALL AXIS(XP,YP,XT,-NXT-NADD,XLEN,ANG,
     $					XASTART,DX,N1,N2,IC)
			ENDIF
		ENDIF
		DZ=(ZAEND-ZASTART)/ZLEN
		IF (NZT.GT.0) THEN
			IF (IAF.EQ.1) THEN
				CALL AXIS2(XP1,YP1,ZT,-NZT-NADD-10000
     $				,ZLEN,BETA,ZASTART,DZ,NMZ,NNZ,
     $				-IABS(MLZ),TSZ,NDZ,SMZ,IC)
			ELSE
				CALL AXIS(XP1,YP1,ZT,-NZT-NADD,
     $				ZLEN,BETA,ZASTART,DZ,N1,N2,IC)
			ENDIF
		ENDIF
	ENDIF
C
C	BEGIN CONTOUR PLOTTING
C
	XXX=NX
	AE=AEND
	AS=ASTART(1)
	NL=IABS(NLEVELS)
	IF (NL.EQ.0) NL=IFIX(ABS(AEND)+0.5)
	IF (NLEVELS.LE.0) THEN
		AE=AMAX
		AS=AMIN
	ENDIF
	DA=0.
	IF (NL.GT.1) DA=(AE-AS)/(NL-1)
C
C	BEGIN CONTOURING
C
	DO 100 IL=1,NL			! FOR EACH LEVEL
	   IF (JF.EQ.2.OR.JF.EQ.4) CALL PLOT(FLOAT(ICOL(6+IL)),0.,0)!COLOR
		IF (JF.GT.2) CALL NEWPEN(ILINE(IL))	! LINE TYPE
		TV=AS+FLOAT(IL-1)*DA	! Z VALUE FOR CONTOUR LEVEL
		IF (NLEVELS.EQ.0) TV=ASTART(IL)
		DO 60 IY=1,IABS(NZ)-1	! FOR EACH Z CELL
			Y1=IY-1
			Y2=IY
			IYY=IY
			IF (IY.GT.1) IYY=IYY-1
			IY2=IY+1
			IF (IY2.LT.NZ) IY2=IY2+1
			DO 50 IX=1,IABS(NX)-1	! FOR EACH X CELL
				X1=IX-1
				X2=IX
				IXX=IX
				IF (IX.GT.1) IXX=IXX-1
				IX2=IX+1
				IF (IX2.LT.NX) IX2=IX2+1
			CALL CNCELPLT3D(TV,XXX,X1,Y1,X2,Y2,TV,A(IX,IY),
     $				A(IX,IY+1),A(IX+1,IY+1),A(IX+1,IY),
     $				A(IXX,IYY),A(IXX,IY2),A(IX2,IY2),A(IX2,IYY))
 50			CONTINUE
C
			IF (IDIR.EQ.0) GOTO 60
C
C	ADD Y CELL EDGES
C
			IX=1
			X1=IX-1
			CALL TRCELPLT3D(IDIR,X1,Y1,X1,Y2,A(IX,IY),
     $				A(IX,IY+1),TV,XXX)
			IX=IABS(NX)
			X1=IX-1
			CALL TRCELPLT3D(IDIR,X1,Y1,X1,Y2,A(IX,IY),
     $				A(IX,IY+1),TV,XXX)
 60		CONTINUE
C
C	NOW ADD X EDGES, EACH SIDE SEPARATELY TO MINIMIZE PEN MOVEMENTS
C
		IF (IDIR.EQ.0) GOTO 100
C
		IY=1
		Y1=IY-1
		DO 70 IX=1,IABS(NX)-1	! FOR EACH X EDGE
			X1=IX-1
			X2=IX
			CALL TRCELPLT3D(IDIR,X1,Y1,X2,Y1,A(IX,IY),
     $				A(IX+1,IY),TV,XXX)
70		CONTINUE
C
		IY=IABS(NZ)
		Y1=IY-1
		DO 80 IX=1,IABS(NX)-1	! FOR EACH X EDGE
			X1=IX-1
			X2=IX
			CALL TRCELPLT3D(IDIR,X1,Y1,X2,Y1,A(IX,IY),
     $				A(IX+1,IY),TV,XXX)
 80		CONTINUE
100	CONTINUE
C
C	FINISH PLOTTING ROUTINE
C
	IF (JF.GT.2) CALL NEWPEN(0)		!RESTORE LINE TYPE
	CALL PLOT(0.,0.,3)			!PEN UP
	IF (IFLAG.GT.0) THEN
		CALL CTERM(2)			!CLEAR TERMINAL
		CALL PLOTND			!CLOSE PLOT OUTPUT
		REPEAT=.FALSE.
	ENDIF
	IF (IFLAG.LT.0) THEN
		REPEAT=.TRUE.
		CALL CTERM(1)			!PUT TERMINAL IN TEXT MODE
	ENDIF
	RETURN
	END
C
C
	SUBROUTINE RVXPT3D(X,Y,AVAL,XR,ZR,XM)
C
C	CREATED BY DAVID LONG    JULY, 1985	AT JPL
C	SUBPROGRAM OF CNT3DX
C
C	ROUTINE TO DETERMINE X,Y VALUE OF A POINT ON 3-D SURFACE
C	FOR CNT3DCX
C
	COMMON /LOCATE/ XSCALE,YSCALE,ZSCALE,AMIN,ALPH,BET
	X=XSCALE*XR*COS(ALPH)+ZR*COS(BET)*ZSCALE
	Y=YSCALE*(AVAL-AMIN)+(XM-XR)*SIN(ALPH)*XSCALE+
     $		ZR*SIN(BET)*ZSCALE
	RETURN
	END
C
C
	SUBROUTINE CNCELPLT3D(ZP,XMAX,X1,Y1,X2,Y2,TV,V1,V2,V3,V4,V5,V6,V7,
     $		V8)
C
C	CREATED BY D. LONG     JULY, 1985	AT JPL
C	SUBPROGRAM OF CNT3DX
C	COMPUTES AND PLOTS CELL SQUARE-SECTIONED CONTOURS IN 3D
C
C	INTERSECTION CODE MAP:
C			  (2)
C			2.   3.
C		    (1)	       (4)
C			1.   4.
C			  (8)
C
	INTEGER SEGCODE
C
	IF=SEGCODE(Y1,Y2,V1,V2,TV,YI1)
	IF=IF+2*SEGCODE(X1,X2,V2,V3,TV,XI2)
	IF=IF+4*SEGCODE(Y2,Y1,V3,V4,TV,YI3)
	IF=IF+8*SEGCODE(X2,X1,V4,V1,TV,XI4)
C
	GOTO (50,50,50,103,50,105,106,107,50,109,110,
     $		111,112,113,114,115) IF+1
	GOTO 50
103	CONTINUE
	CALL RVXPT3D(PX,PY,ZP,X1,YI1,XMAX)
	CALL PLOT(PX,PY,3)
	CALL RVXPT3D(PX,PY,ZP,XI2,Y2,XMAX)
	CALL PLOT(PX,PY,2)
	GOTO 50
105	CONTINUE
	CALL RVXPT3D(PX,PY,ZP,X1,YI1,XMAX)
	CALL PLOT(PX,PY,3)
	CALL RVXPT3D(PX,PY,ZP,X2,YI3,XMAX)
	CALL PLOT(PX,PY,2)
	GOTO 50
106	CONTINUE
	CALL RVXPT3D(PX,PY,ZP,XI2,Y2,XMAX)
	CALL PLOT(PX,PY,3)
	CALL RVXPT3D(PX,PY,ZP,X2,YI3,XMAX)
	CALL PLOT(PX,PY,2)
	GOTO 50
107	CONTINUE
	IF (V3.EQ.TV) GOTO 103
	GOTO 106
109	CONTINUE
	CALL RVXPT3D(PX,PY,ZP,X1,YI1,XMAX)
	CALL PLOT(PX,PY,3)
	CALL RVXPT3D(PX,PY,ZP,XI4,Y1,XMAX)
	CALL PLOT(PX,PY,2)
	GOTO 50
110	CONTINUE
	CALL RVXPT3D(PX,PY,ZP,XI4,Y1,XMAX)
	CALL PLOT(PX,PY,3)
	CALL RVXPT3D(PX,PY,ZP,XI2,Y2,XMAX)
	CALL PLOT(PX,PY,2)
	GOTO 50
111	CONTINUE
	IF (V1.EQ.TV) GOTO 103
	GOTO 109
112	CONTINUE
	CALL RVXPT3D(PX,PY,ZP,XI4,Y1,XMAX)
	CALL PLOT(PX,PY,3)
	CALL RVXPT3D(PX,PY,ZP,X2,YI3,XMAX)
	CALL PLOT(PX,PY,2)
	GOTO 50
113	CONTINUE
	IF (V1.EQ.TV) GOTO 112
	GOTO 109
114	CONTINUE
	IF (V3.EQ.TV) GOTO 112
	GOTO 106
115	CONTINUE
	IF (V1.EQ.TV) GOTO 50
	C1=POLY1INT(V5,V1,V3,V7,1.5)
	C2=POLY1INT(V6,V2,V4,V8,1.5)
	C=(C1+C2)/2.
	IF (C.GT.TV) THEN
		IF (V1.GT.TV) THEN
			CALL RVXPT3D(PX,PY,ZP,X1,YI1,XMAX)
			CALL PLOT(PX,PY,3)
			CALL RVXPT3D(PX,PY,ZP,XI2,Y2,XMAX)
			CALL PLOT(PX,PY,2)
			GOTO 112
		ELSE
			CALL RVXPT3D(PX,PY,ZP,X1,YI1,XMAX)
			CALL PLOT(PX,PY,3)
			CALL RVXPT3D(PX,PY,ZP,XI4,Y1,XMAX)
			CALL PLOT(PX,PY,2)
			GOTO 106
		ENDIF
	ELSE
		IF (V1.LT.TV) THEN
			CALL RVXPT3D(PX,PY,ZP,X1,YI1,XMAX)
			CALL PLOT(PX,PY,3)
			CALL RVXPT3D(PX,PY,ZP,XI2,Y2,XMAX)
			CALL PLOT(PX,PY,2)
			GOTO 112
		ELSE
			CALL RVXPT3D(PX,PY,ZP,X1,YI1,XMAX)
			CALL PLOT(PX,PY,3)
			CALL RVXPT3D(PX,PY,ZP,XI4,Y1,XMAX)
			CALL PLOT(PX,PY,2)
			GOTO 106
		ENDIF
	ENDIF
 50	RETURN
	END
C
C
	SUBROUTINE TRCELPLT3D(IDIR,X1,Y1,X2,Y2,V1,V2,TV,XMAX)
C
C	CREATED BY D. LONG     JULY, 1985	AT JPL
C	SUBPROGRAM OF CNT3DX
C	COMPUTES AND PLOTS WHERE A LINE SEGMENT CROSSES A THRESHOLD
C	VALUE.
C
C	IDIR		(I)	DIRECTION:  < 0 LESS, > 0 GREATER
C	X1,Y1,X2,Y2	(R)	START, END POINTS OF LINE SEGMENT
C	V1,V2		(R)	VALUE OF FUNCTION AT START, END OF LINE
C	TV		(R)	THRESHOLD VALUE
C	XMAX		(R)	MAXIMUM X VALUE (USED FOR SCALING)
C
	LOGICAL IF1,IF2
C
	IF1=.FALSE.
	IF2=.FALSE.
	IF (IDIR.LT.0) THEN
		IF (V1.LT.TV) IF1=.TRUE.
		IF (V2.LT.TV) IF2=.TRUE.
	ELSE
		IF (V1.GT.TV) IF1=.TRUE.
		IF (V2.GT.TV) IF2=.TRUE.
	ENDIF
	IF (IF1.AND.IF2) THEN
		CALL RVXPT3D(PX,PY,TV,X1,Y1,XMAX)
		CALL PLOT(PX,PY,3)
		CALL RVXPT3D(PX,PY,TV,X2,Y2,XMAX)
		CALL PLOT(PX,PY,2)
		RETURN
	ENDIF
	IF (IF1.OR.IF2) THEN
		IF=ISEGCODE(X1,Y1,X2,Y2,V1,V2,TV,XI,YI)
		IF (IF.NE.0) THEN
			IF (IF1) THEN
				CALL RVXPT3D(PX,PY,TV,X1,Y1,XMAX)
				CALL PLOT(PX,PY,3)
				CALL RVXPT3D(PX,PY,TV,XI,YI,XMAX)
				CALL PLOT(PX,PY,2)
			ELSE
				CALL RVXPT3D(PX,PY,TV,X2,Y2,XMAX)
				CALL PLOT(PX,PY,3)
				CALL RVXPT3D(PX,PY,TV,XI,YI,XMAX)
				CALL PLOT(PX,PY,2)
			ENDIF
		ENDIF
	ENDIF
	RETURN
	END
C
C
	INTEGER FUNCTION ISEGCODE(X1,Y1,X2,Y2,V1,V2,TV,XI,YI)
C
C	CREATED BY D. LONG  JULY, 1985
C	SUBPROGRAM OF CNT3DX
C
C	ROUTINE TO COMPUTE WHERE A LINE IN 2-SPACE CROSSES
C	A THRESHOLD VALUE
C
C	X1,Y1,X2,Y2	(R)	START, END POINTS OF LINE
C	V1,V2		(R)	VALUE OF FUNCTION AT START, END POINTS OF LINE
C	TV		(R)	THRESHOLD VALUE
C	XI,YI		(R)	THRESHOLD POINT (RETURNED)
C
C	ISEGCODE RETURNS:
C				0 = NO INTERSECTION
C				1 = INTERSECTION
C
	ISEGCODE=0
	IF ((V1.LE.TV.AND.V2.GE.TV).OR.(V1.GE.TV.AND.V2.LE.TV)) THEN
		DV=V2-V1
		XD=(X2-X1)/DV
		IF (XD.EQ.0.0) THEN
			XD=(Y2-Y1)/DV
			IF (XD.EQ.0.0) RETURN
			YI=(TV-V1)*XD+Y1
			XI=X1
		ELSE
			XI=(TV-V1)*XD+X1
			YI=(Y2-Y1)*(XI-X1)/(X2-X1)+Y1
		ENDIF
		ISEGCODE=1
	ENDIF
	RETURN
	END
C
C *************************************************************************
C
	SUBROUTINE MESH3D(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,
     $		IFLAG,IAXIS,XT,NXT,XASTART,XAEND,YT,NYT,
     $		ZT,NZT,ZASTART,ZAEND,AMININ,AMAXIN,ICOL)
C
C	CREATED BY D. LONG  JAN 1986	AT JPL
C
C	SIMPLIFIES CALLING MESH3DX ROUTINE AXISES
C
	DIMENSION A(INX,INZ),ICOL(1)
	INTEGER XT(1),YT(1),ZT(1)
	IAX=MOD(IAXIS,10)
	IF (IAXIS.LT.0) THEN
		AMN=AMININ
		AMX=AMAXIN
	ENDIF
	IF (MOD(IFLAG,10).EQ.2) THEN
		CALL MESH3DX(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,IFLAG,IAX,
     $			XT,NXT,XASTART,XAEND,NMX,NNX,MLX,TSX,NDX,SMX,
     $			YT,NYT,NMY,NNY,MLY,TSY,NDY,SMY,
     $			ZT,NZT,ZASTART,ZAEND,NMZ,NNZ,MLZ,TSZ,NDZ,SMZ,
     $			AMN,AMX,ICOL)
	ELSE
		CALL MESH3DX(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,IFLAG,IAX,
     $			XT,NXT,XASTART,XAEND,NMX,NNX,MLX,TSX,NDX,SMX,
     $			YT,NYT,NMY,NNY,MLY,TSY,NDY,SMY,
     $			ZT,NZT,ZASTART,ZAEND,NMZ,NNZ,MLZ,TSZ,NDZ,SMZ,
     $			AMN,AMX,IC)
	ENDIF
	RETURN
	END
C
C
	SUBROUTINE MESH3DX(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,
     $		IFLAG,IAXIS,
     $		XT,NXT,XASTART,XAEND,NMX,NNX,MLX,TSX,NDX,SMX,
     $		YT,NYT,NMY,NNY,MLY,TSY,NDY,SMY,
     $		ZT,NZT,ZASTART,ZAEND,NMZ,NNZ,MLZ,TSZ,NDZ,SMZ,
     $		AMININ,AMAXIN,ICOL)
C
C	CREATED BY D. LONG     JAN 1986
C
C	ROUTINE TO PLOT DATA IN 3-D OVERLAY FORM
C	COORDINATE SYSTEM IS:		Z Y		Y  Z
C			DOCUMENTED:	|/	NAMES:	|/
C					 \ X		 \X
C
C	A	REAL ARRAY A(INX,INZ) CONTAINING VERTICAL HEIGHT DATA
C	INX,INZ INTEGERS DIMENSION OF A ARRAY
C	NX,NZ	INTEGERS INDICATING SIZE OF A ARRAY TO PLOT
C	ALPHA	REAL ANGLE (IN DEGREES) OF X AXIS (NX) FROM HORIZONTAL
C	BETA	REAL ANGLE (IN DEGREES) OF Z AXIS (NZ) FROM HORIZONTAL
C	XH,YH,ZH REAL LENGTH OF EACH AXIS
C	IFLAG	INTEGER
C		>10000	REPEAT PLOTTING BUT DO NOT INTIALIZE PLOTTER
C		< 0	REPEAT PLOTTING (DON'T CLOSE PLOTTER OUTPUT
C		= 0	CLOSE PLOTTER OUTPUT--DO NOT PRODUCE PLOT
C		> 0	SINGLE PLOT OUTPUT ONLY (PLOTTER OUTPUT CLOSED)
C 	(ONE'S DIGIT) = 2 USE PEN COLOR CONTROL ARRAY
C		      = 1 DO NOT USE PEN COLOR ARRAY
C	(TEN'S DIGIT) = 0 PLOT SIDE PLATES
C		      = 1 DO NOT PLOT SIDE PLATES
C 	(HUNDREDS'S DIGIT) = 0 ASK WHICH SCREEN DEVICE TO USE
C		           <>0 SCREEN DEVICE CODE NUMBER
C 	IAXIS	INTEGER AXIS OPTION FLAG
C			= 0	DO NOT PLOT AXIS--FOLLOWING VARIABLES NOT REQUIRED
C			< 0	PLOT AXIS, USE INPUT Y AXIS SCALE--FOLLOWING VARIABLES REQUIRED
C			> 0	PLOT AXIS, USE COMPUTED Y AXIS SCALE--FOLLOWING VARIABLES REQUIRED
C 	(ONE'S DIGIT)	= 1	PLOT AXIS, Y AXIS SCALE--VARIABLES REQUIRED
C			= 2	PLOT AXIS, AUTO SCALE Y AXIS--VARIABLES REQUIRED
C	(TEN'S DIGIT)	= 0	DEFAULT AXIS PARAMETERS
C			= 1	SPECIALIZED AXIS2 PARAMETERS
C 	XT,YT,ZT	CHAR STRINGS FOR AXIS TITLES
C 	NXT,NYT,NZT	INT  LENGTH OF AXIS TITLES
C			     IF ZERO THEN THAT AXIS NOT PLOTTED
C 	XASTART,ZASTART	REAL AXIS START VALUES
C 	XAEND,ZAEND	REAL AXIS END VALUES
C FOLLOWING ONLY REQUIRED IF TEN'S DIGIT OF IFLAG=1
C	NMX,NMY,NMZ	INT NUMBER OF MINOR TICKS BETWEEN MAJOR TICKS
C	NNX,NNY,NNZ	INT HIGHLIGHT LENGTH OF NNX-TH MINOR TICK ON AXIS
C	MLX,MLY,MLZ	INT NUMBER OF MAJOR TICK MARKS ON AXIS
C	TSX,TSY,TSZ	REAL SIZE OF TITLE AND NUMBERS OF AXIS
C			  IF LESS THAN ZERO DO NOT AUTO-SCALE BY (x10^POWER)
C 	NDX,NDY,NDZ	INT NUMBER OF DIGITS TO RIGHT OF DECIMAL POINT
C 	SMX,SMY,SMZ	REAL MAJOR TICK LENGTH
C 	AMININ,AMAXIN 	REAL YAXIS SCALING FACTORS (ONLY NEEDED IF IAXIS < 0)
C	ICOL		INTEGER COLOR CONTROL (REQUIRED IF MAG(IFLAG)=2)
C				ICOL(1) AXIS LINE COLOR
C				ICOL(2) AXIS NUMBERS COLOR
C				ICOL(3) AXIS TITLE COLOR
C				ICOL(4) AXIS TITLE COLOR
C				ICOL(5) PLOT COLOR
C
	DIMENSION A(INX,INZ),AS(2),ICOL(5),IC(4)
	INTEGER XT(1),YT(1),ZT(1)
	LOGICAL FLAG,HHIGH,REPEAT
	COMMON /LOCATE/ XSCALE,YSCALE,ZSCALE,AMIN,ALPH,BET
	DATA TPI/3.141592654/,REPEAT/.FALSE./
C
	IF (IFLAG.EQ.0) THEN
		IF (REPEAT) CALL PLOTND	!CLOSE PLOTTER
		REPEAT=.FALSE.
		RETURN
	ENDIF
	ALPH=ALPHA*TPI/180.		!X-AXIS INCLINATION 0-80 DEGS
	BET=BETA*TPI/180.		!Z-AXIS ANGLE 5-80 DEGS
C
	IF (IAXIS.LT.0) THEN
		AMAX=AMAXIN
		AMIN=AMININ
	ELSE
		AMAX=A(1,1)
		AMIN=A(1,1)
		DO 16IZ=1,NZ			!DETERMINE MAX,MIN ARRAY VALUES
			DO 16 IX=1,NX
				AMAX=AMAX1(AMAX,A(IX,IZ))
				AMIN=AMIN1(AMIN,A(IX,IZ))
16		CONTINUE
	ENDIF
	IF (ALPHA.LT.0..OR.ALPHA.GT.88..OR.BETA.LT.1..OR.BETA.GT.90.)THEN
		WRITE(*,3000)
3000		FORMAT(' *** MESH3DX INPUT ANGLE ERROR ***')
		RETURN
	ENDIF
	IF (AMAX.EQ.AMIN) THEN
		WRITE(*,3001)
3001		FORMAT(' *** MESH3DX ERROR *** MAX=MIN')
		AMAX=AMIN+1.
	ENDIF
C
	XLEN=ABS(XH)
	XSCALE=XLEN/FLOAT(NX-1)
	ZLEN=ABS(ZH)
	ZSCALE=ZLEN/FLOAT(NZ-1)
	YLEN=ABS(YH)
	IF (MOD(IABS(IAXIS),10).EQ.2) THEN
		AS(1)=AMAX
		AS(2)=AMIN
		CALL SCALE(AS,YLEN,2,1,1,AMIN,DAA)
		AMAX=YLEN*DAA+AMIN
	ENDIF
	YSCALE=1.0
	IF (AMAX-AMIN.NE.0.0) YSCALE=YLEN/(AMAX-AMIN)
C
C	INTIALIZE PLOT PACKAGE
C
	JF=IABS(IFLAG)
	IF (.NOT.REPEAT.AND.JF.LT.10000) THEN
		ILU=JF/100
		CALL FRAME(3,ILU,1.5,0.65,1.)		!INTIALIZE
	ELSE
		CALL CTERM(-1)				!PUT TERMINAL PLOT MODE
	ENDIF
C
	IAF=IABS(IAXIS)/10
	JFF=MOD(JF,100)/100
	JF=MOD(JF,10)
	IF (IAXIS.NE.0) THEN		!PLOT AXIS LABELS
		NADD=0
		IF (JF.EQ.2) THEN
			IC(1)=ICOL(1)
			IC(2)=ICOL(2)
			IC(3)=ICOL(3)
			IC(4)=ICOL(4)
			NADD=100000	!PEN COLOR
		ENDIF
		CALL VXPT3D(XP,YP,AMIN,1,1,NX)
		DY=(AMAX-AMIN)/YLEN
		IF (NYT.GT.0) THEN 	!PLOT Y AXIS
			IF (IAF.EQ.1) THEN
				CALL AXIS2(XP,YP,YT,NYT+11000+NADD,
     $				YLEN,90.,AMIN,DY,NMY,NNY,-IABS(MLY),
     $				TSY,NDY,SMY,IC)
			ELSE
				CALL AXIS(XP,YP,YT,NYT+1000+NADD,
     $					YLEN,90.,AMIN,DY,N1,N2,IC)
			ENDIF
		ENDIF
		CALL VXPT3D(XP1,YP1,AMIN,NX,1,NX)
		DX=(XAEND-XASTART)/XLEN
		ANG=ATAN2(YP1-YP,XP1-XP)*180./TPI
		IF (NXT.GT.0) THEN
			IF (IAF.EQ.1) THEN
				CALL AXIS2(XP,YP,XT,-NXT-NADD-10000,XLEN,ANG,
     $				XASTART,DX,NMX,NNX,-IABS(MLX),TSX,NDX,SMX,IC)
			ELSE
				CALL AXIS(XP,YP,XT,-NXT-NADD,XLEN,ANG,
     $					XASTART,DX,N1,N2,IC)
			ENDIF
		ENDIF
		DZ=(ZAEND-ZASTART)/ZLEN
		IF (NZT.GT.0) THEN
			IF (IAF.EQ.1) THEN
				CALL AXIS2(XP1,YP1,ZT,-NZT-NADD-10000
     $				,ZLEN,BETA,ZASTART,DZ,NMZ,NNZ,
     $				-IABS(MLZ),TSZ,NDZ,SMZ,IC)
			ELSE
				CALL AXIS(XP1,YP1,ZT,-NZT-NADD,
     $				ZLEN,BETA,ZASTART,DZ,N1,N2,IC)
			ENDIF
		ENDIF
	ENDIF
	IF (JF.EQ.2) CALL PLOT(FLOAT(ICOL(5)),0.,0) !COLOR
C
C	PLOT FRONT PLATE
C
	IPEN=3
	DO 14 I=1,NX
		CALL VXPT3D(XP1,YP1,A(I,1),I,1,NX)
		CALL PLOT(XP1,YP1,IPEN)		 !PLOT SIDE LINE
		IPEN=2
14	CONTINUE
	IHOLD=NX
	IF (BETA.EQ.90.) GOTO 5
	IF (JFF.EQ.1) GOTO 71			! DON'T PLOT SIDE PLATES
	CALL VXPT3D(XP,YP,AMIN,NX,1,NX)
	CALL PLOT(XP,YP,2)
	DO 19 I=1,NX-1				!ADD SIDE LINES
		CALL VXPT3D(XP1,YP1,A(I,1),I,1,NX)
		CALL PLOT(XP1,YP1,3)
		CALL VXPT3D(XP,YP,AMIN,I,1,NX)
		CALL PLOT(XP,YP,2)
		CALL VXPT3D(XP,YP,AMIN,I+1,1,NX)
		CALL PLOT(XP,YP,2)
19	CONTINUE
C
C	PLOT SIDE PLATE
C
71	CALL VXPT3D(XP1,YP1,A(NX,1),NX,1,NX)
	CALL PLOT(XP1,YP1,3)
	DO 23 I=1,NZ				!PLOT RIGHT SIDE CURVE
		CALL VXPT3D(XP,YP,A(NX,I),NX,I,NX)
		CALL PLOT(XP,YP,2)
23	CONTINUE
	CALL VXPT3D(XP,YP,AMIN,NX,1,NX)
	CALL PLOT(XP,YP,3)
	IHOLD=NX+NZ				!NUMBER OF H VALUES
	IF (JFF.EQ.1) GOTO 5			! DON'T PLOT SIDE PLATES
	DO 24 I=2,NZ				!ADD SIDE LINES
		CALL VXPT3D(XP2,YP2,AMIN,NX,I,NX)
		CALL PLOT(XP2,YP2,2)
		CALL VXPT3D(XP,YP,A(NX,I),NX,I,NX)
		CALL PLOT(XP,YP,2)
		CALL PLOT(XP,YP2,3)
24	CONTINUE
C
C	PLOT MESH
C
   5	DO 500 IZ=2,NZ
		IP=3
		DO 500 IX=1,NX
			CALL VXPT3D(XP1,YP1,A(IX,IZ),IX,IZ,NX)
			CALL PLOT(XP1,YP1,IP)
			IP=2
500	CONTINUE
	DO 600 IX=1,NX-1
		IP=3
		DO 600 IZ=1,NZ
			CALL VXPT3D(XP1,YP1,A(IX,IZ),IX,IZ,NX)
			CALL PLOT(XP1,YP1,IP)
			IP=2
600	CONTINUE
C
	CALL PLOT(0.,0.,3)			!PEN UP
	IF (IFLAG.GT.0) THEN
		CALL CTERM(2)			!CLEAR TERMINAL
		CALL PLOTND			!CLOSE PLOT OUTPUT
		REPEAT=.FALSE.
	ENDIF
	IF (IFLAG.LT.0) THEN
		REPEAT=.TRUE.
		CALL CTERM(1)			!PUT TERMINAL IN TEXT MODE
	ENDIF
	RETURN
	END
C
C *************************************************************************
C
	SUBROUTINE MVAX3D(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,
     $		IFLAG,IAXIS,
     $		XT,NXT,XASTART,XAEND,YT,NYT,ZT,NZT,ZASTART,ZAEND,
     $		AMININ,AMAXIN,ICOL)
C
C	CREATED BY D. LONG  AUG 1987	AT JPL
C
C	SIMPLIFIES CALLING MVAX3DX ROUTINE
C
	DIMENSION A(INX,INZ),ICOL(1)
	INTEGER XT(1),YT(1),ZT(1)
	IAX=MOD(IAXIS,100)
	IF (IAXIS.LT.0) THEN
		AMN=AMININ
		AMX=AMAXIN
	ENDIF
	IF (MOD(IABS(IFLAG),10).EQ.2) THEN
		CALL MVAX3DX(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,IFLAG,IAX,
     $			XT,NXT,XASTART,XAEND,TX,TSX,FDX,
     $			YT,NYT,TY,TSY,FDY,
     $			ZT,NZT,ZASTART,ZAEND,TZ,TSZ,FDZ,
     $			AMN,AMX,ICOL)
	ELSE
		CALL MVAX3DX(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,IFLAG,IAX,
     $			XT,NXT,XASTART,XAEND,TX,TSX,FDX,
     $			YT,NYT,TY,TSY,FDY,
     $			ZT,NZT,ZASTART,ZAEND,TZ,TSZ,FDZ,
     $			AMN,AMX,IC)
	ENDIF
	RETURN
	END
C
C ********************************************************************
C
	SUBROUTINE MVAX3DX(A,INX,INZ,NX,NZ,ALPHA,BETA,XH,YH,ZH,
     $		IFLAG,IAXIS,
     $		XT,NXT,XASTART,XAEND,TX,TSX,FDX,
     $		YT,NYT,TY,TSY,FDY,
     $		ZT,NZT,ZASTART,ZAEND,TZ,TSZ,FDZ,
     $		AMININ,AMAXIN,ICOL)
C
C	CREATED BY D. LONG     AUG 1987	AT JPL
C
C	ROUTINE TO PLOT DATA IN 3-D MESH OR HISTOGRAM COLUMN FORM
C	WITH HIDDEN LINE REMOVAL USING PLT3D OR HLT3D
C
C	COORDINATE SYSTEM HAS ORIGIN AT UPPER LEFT CORNER
C					Y
C			VARIABLE NAMES:	|	
C				      Z/ \X
C
C	A	REAL ARRAY A(INX,INZ) CONTAINING VERTICAL HEIGHT DATA
C	INX,INZ INTEGERS DIMENSION OF A ARRAY
C	NX,NZ	INTEGERS INDICATING SIZE OF A ARRAY TO PLOT
C	ALPHA	REAL ANGLE (IN DEGREES) OF X AXIS (NX) (ALTITUDE)
C	BETA	REAL ANGLE (IN DEGREES) OF Z AXIS (NZ) (AZIMUTH)
C	XH,YH,ZH REAL LENGTH OF EACH AXIS
C	IFLAG	INTEGER
C		>10000	REPEAT PLOTTING BUT DO NOT INTIALIZE PLOTTER
C		< 0	REPEAT PLOTTING (DON'T CLOSE PLOTTER OUTPUT
C		= 0	CLOSE PLOTTER OUTPUT--DO NOT PRODUCE PLOT
C		> 0	SINGLE PLOT OUTPUT ONLY (PLOTTER OUTPUT CLOSED)
C 	(ONE'S DIGIT) = 2 USE PEN COLOR CONTROL ARRAY
C		      = 1 DO NOT USE PEN COLOR ARRAY
C	(TEN'S DIGIT) = 0 PLOT MESH WITH SIDE PLATES (LOWER SURFACE NOT SHOWN)
C		      = 1 MESH W/O SIDE PLATES (LOWER SIDE SURFACE SHOWN
C			  USING SOLID LINE)
C		      = 2 MESH W/O SIDE PLATES (LOWER SIDE SURFACE SHOWN
C			  USING DOTTED LINE)
C		      = 3 MESH W/O SIDE PLATES (LOWER SIDE SURFACE NOT SHOWN)
C		      = 4 HISTOGRAM COLUMNS (LOWER SIDE SURFACE SHOWN
C			  USING SOLID LINE)
C		      = 5 HISTOGRAM COLUMNS (LOWER SIDE SURFACE SHOWN
C			  USING DOTTED LINE)
C		      = 6 HISTOGRAM COLUMNS (LOWER SIDE SURFACE NOT SHOWN)
C 	(HUNDREDS'S DIGIT) = 0 ASK WHICH SCREEN DEVICE TO USE
C		           <>0 SCREEN DEVICE CODE NUMBER
C 	IAXIS	INTEGER AXIS OPTION FLAG
C			= 0	DO NOT PLOT AXIS--FOLLOWING VARIABLES NOT REQUIRED
C			< 0	PLOT AXIS, USE INPUT Y AXIS SCALE--FOLLOWING VARIABLES REQUIRED
C			> 0	PLOT AXIS, USE COMPUTED Y AXIS SCALE--FOLLOWING VARIABLES REQUIRED
C 	(ONE'S DIGIT)	= 1	PLOT AXIS, Y AXIS SCALE--VARIABLES REQUIRED
C			= 2	PLOT AXIS, AUTO SCALE Y AXIS--VARIABLES REQUIRED
C	(TEN'S DIGIT)	= 0	BACK PLANE PLOTTED
C			= 1	BACK PLANE NOT PLOTTED
C	(HUNDRED'S)	= 0	DEFAULT AXIS PARAMETERS
C			= 1	SPECIALIZED AXIS3 PARAMETERS
C 	XT,YT,ZT	CHAR STRINGS FOR AXIS TITLES
C 	NXT,NYT,NZT	INT  LENGTH OF AXIS TITLES
C			     IF ZERO THEN THAT AXIS NOT PLOTTED
C 	XASTART,ZASTART	REAL AXIS START VALUES
C 	XAEND,ZAEND	REAL AXIS END VALUES
C FOLLOWING ONLY REQUIRED IF TEN'S DIGIT OF IAXIS=1
C	TX,TY,TZ	REAL TICK MARK PATTERN (SEE AXIS3)
C	TSX,TSY,TSZ	REAL SIZE OF TITLE AND NUMBERS OF AXIS
C			  IF <0 DO NOT AUTO-SCALE AXIS BY (x10^POWER)
C 	FDX,FDY,FDZ	REAL AXIS NUMBER LABEL FORMAT (SEE AXIS3)
C 	AMININ,AMAXIN 	REAL YAXIS SCALING FACTORS (ONLY NEEDED IF IAXIS < 0)
C	ICOL		INTEGER COLOR CONTROL (REQUIRED IF MOD(IFLAG,10)=2)
C				ICOL(1) AXIS LINE COLOR
C				ICOL(2) AXIS NUMERIC LABEL COLOR
C				ICOL(3) AXIS TITLE COLOR
C				ICOL(4) AXIS EXPONENT COLOR
C				ICOL(5) BACK PLANE COLOR (RETURN)
C				ICOL(6) TOP SURFACE COLOR
C				ICOL(7) BOTTOM SURFACE COLOR
C
	DIMENSION A(INX,INZ),AS(2),ICOL(1),IC(4)
	INTEGER XT(1),YT(1),ZT(1)
	LOGICAL REPEAT
	DATA TPI/3.141592654/,REPEAT/.FALSE./
C
C	WORKING SPACE
C
	PARAMETER (NW2D0=6000)
	DIMENSION W2(NW2D0)
C
	COMMON /PLT3B/A1,A2,A3,B1,B2,B3,B4
C
	XFORM(I,J,AV)=A1*J+A2*I+A3
	YFORM(I,J,AV)=B1*J+B2*I+B3*AV+B4
C
C	INTIALIZE ROUTINE AND PLOT PACKAGE IF REQUIRED
C
	IF (IFLAG.EQ.0) THEN
		IF (REPEAT) CALL PLOTND	!CLOSE PLOTTER
		REPEAT=.FALSE.
		RETURN
	ENDIF
C
	IF (IAXIS.LT.0) THEN
		AMAX=AMAXIN
		AMIN=AMININ
	ELSE
		AMAX=A(1,1)
		AMIN=A(1,1)
		DO 16IZ=1,NZ			!DETERMINE MAX,MIN ARRAY VALUES
			DO 16 IX=1,NX
				AMAX=AMAX1(AMAX,A(IX,IZ))
				AMIN=AMIN1(AMIN,A(IX,IZ))
16		CONTINUE
	ENDIF
	XLEN=ABS(XH)
	ZLEN=ABS(ZH)
	YLEN=ABS(YH)
	IF (MOD(IABS(IAXIS),10).EQ.2) THEN
		AS(1)=AMAX
		AS(2)=AMIN
		CALL SCALE(AS,YLEN,2,1,1,AMIN,DAA)
		AMAX=YLEN*DAA+AMIN
	ENDIF
	YSCALE=1.0
	IF (AMAX-AMIN.NE.0.0) YSCALE=YLEN/(AMAX-AMIN)
C
C	INTIALIZE PLOT PACKAGE
C
	JF=IABS(IFLAG)
	IF (.NOT.REPEAT.AND.JF.LT.10000) THEN
		ILU=JF/100				!GRAPHICS DEVICE CODE
		CALL FRAME(3,ILU,1.5,1.0,1.)		!INTIALIZE
	ELSE
		CALL CTERM(-1)				!PUT TERMINAL IN PLOT MODE
	ENDIF
C
	IAFF=IABS(IAXIS)/100				!AXIS TYPE
	IAF=MOD(IABS(IAXIS),100)/10			!BACK PANEL
	JFF=MOD(JF,100)/10				!SIDE PLATES/SUFACE
	JF=MOD(JF,10)					!COLORS
C
C	PLOT SURFACE WITH SIMPLE HIDDEN LINE REMOVAL
C
	XP=XLEN/2.*COSD(ALPHA)+2.0
	YP=-(XLEN/2.+YLEN/2.)*SIND(ALPHA)*SIND(BETA+180.)-YSCALE*AMIN
	NW1D=1
	NW2D=NW2D0-10
	IF (JFF.LT.4) THEN
		NW1D=4*MAX(NX,NZ)
		NW2D=NW2D0-NW1D-1
		IF (NW2D.LT.NW1D) GOTO 42
	ENDIF
	NW=NW2D+1
C
	IF (JFF.NE.0.AND.JFF.NE.3.AND.JFF.NE.6) THEN
C
C	IF WE DON'T PLOT SIDE PLATES THEN PLOT UNDERSIDE OF SURFACE
C
		IF (JFF.EQ.1.OR.JFF.EQ.4) CALL NEWPEN(1)
		IF (JF.EQ.2) CALL PLOT(FLOAT(ICOL(7)),0.,0)
		IF (JFF.LT.3) THEN
		 CALL PLT3D(A,INX,INZ,NX,NZ,W2(NW),NW1D,W2,NW2D,
     $		 ALPHA,180.+BETA,-XLEN,XP,ZLEN,YP,YSCALE,0.,IERR)
		ELSE
		 CALL HLT3D(A,INX,INZ,NX,NZ,W2,NW1D,W2,NW2D,
     $		 ALPHA,180.+BETA,-XLEN,XP,ZLEN,YP,YSCALE,0.,IERR)
		ENDIF
		IF (JFF.EQ.1.OR.JFF.EQ.4) CALL NEWPEN(0)
		IF (IERR.NE.0) GOTO 42
C
C	IF BACK PANEL IS DESIRED, PLOT LOWER SIDE OF BACK PANEL
C
	IF (IAXIS.NE.0) THEN
		DY=1./YSCALE
		IF (NYT.GT.0) THEN 	!PLOT Y AXIS
			IF (IAFF.EQ.1) THEN
			  N1=INT(TY)
			ELSE
			  N1=IFIX(YLEN+.5)+1
			ENDIF
			IF (IAF.EQ.0) THEN
		IF (JF.EQ.2) CALL PLOT(FLOAT(ICOL(5)),0.,0)
				 VAL2=(N1-1)*DY+AMIN
				 W2(  NW)=XFORM(1,NZ,VAL2)
				 W2(1+NW)=YFORM(1,NZ,VAL2)
				 W2(2+NW)=XFORM(1,1,VAL2)
				 W2(3+NW)=YFORM(1,1,VAL2)
				 W2(4+NW)=XFORM(NX,1,VAL2)
				 W2(5+NW)=YFORM(NX,1,VAL2)
			CALL NXTVU(-2,W2(NW),3,W2,NW2D,IERR)
				 IF (IERR.NE.0) GOTO 42
				DO 338 K=1,N1-1
				 VAL1=(N1-K-1)*DY+AMIN
				 W2(  NW)=XFORM(1,NZ,VAL2)
				 W2(1+NW)=YFORM(1,NZ,VAL2)
				 W2(2+NW)=XFORM(1,NZ,VAL1)
				 W2(3+NW)=YFORM(1,NZ,VAL1)
				 W2(4+NW)=XFORM(1,1,VAL1)
				 W2(5+NW)=YFORM(1,1,VAL1)
				 W2(6+NW)=XFORM(1,1,VAL2)
				 W2(7+NW)=YFORM(1,1,VAL2)
			CALL NXTVU(-2,W2(NW),4,W2,NW2D,IERR)
				 IF (IERR.NE.0) GOTO 42
				 W2(  NW)=XFORM(1,1,VAL1)
				 W2(1+NW)=YFORM(1,1,VAL1)
				 W2(2+NW)=XFORM(NX,1,VAL1)
				 W2(3+NW)=YFORM(NX,1,VAL1)
				 W2(4+NW)=XFORM(NX,1,VAL2)
				 W2(5+NW)=YFORM(NX,1,VAL2)
			CALL NXTVU(-2,W2(NW),3,W2,NW2D,IERR)
				 IF (IERR.NE.0) GOTO 42
338				CONTINUE
			ENDIF
		ENDIF
	ENDIF
C
	ENDIF
C
C	PLOT TOP SIDE OF SURFACE
C
	IF (JF.EQ.2) CALL PLOT(FLOAT(ICOL(6)),0.,0)
	IF (JFF.LT.4) THEN
	   CALL PLT3D(A,INX,INZ,NX,NZ,W2(NW),NW1D,W2,NW2D,ALPHA,
     $		180.+BETA,XLEN,XP,ZLEN,YP,YSCALE,0.,IERR)
	ELSE
	   CALL HLT3D(A,INX,INZ,NX,NZ,W2,NW1D,W2,NW2D,ALPHA,
     $		180.+BETA,XLEN,XP,ZLEN,YP,YSCALE,0.,IERR)
	ENDIF
C
	IF (IERR.NE.0) THEN
42		CALL CTERM(1)
		WRITE(*,1) IERR
1	FORMAT(' *** ERROR CALLING PLT3D/HLT3D IN MVAX3DX *** '/
     $		' *** INTERNAL WORK SPACE EXCEEDED ***',I2)
		RETURN
	ENDIF
C
C	ADD SIDE PLATES
C
	IF (JFF.NE.0) GOTO 71			! DON'T PLOT SIDE PLATES
	DO 4335 I=1,NX
		XP=XFORM(I,NZ,AMIN)
		YP=YFORM(I,NZ,AMIN)
		XP1=XFORM(I,NZ,A(I,NZ))
		YP1=YFORM(I,NZ,A(I,NZ))
		IF (MOD(I,2).EQ.0) THEN
			CALL PLOT(XP,YP,3)
			CALL PLOT(XP1,YP1,2)
		ELSE
			CALL PLOT(XP1,YP1,3)
			CALL PLOT(XP,YP,2)
		ENDIF
4335	CONTINUE
	DO 4336 J=2,NZ
		JJ=NZ-J+1
		XP=XFORM(NX,JJ,AMIN)
		YP=YFORM(NX,JJ,AMIN)
		XP1=XFORM(NX,JJ,A(NX,JJ))
		YP1=YFORM(NX,JJ,A(NX,JJ))
		IF (MOD(J,2).EQ.0) THEN
			CALL PLOT(XP,YP,3)
			CALL PLOT(XP1,YP1,2)
		ELSE
			CALL PLOT(XP1,YP1,3)
			CALL PLOT(XP,YP,2)
		ENDIF
4336	CONTINUE
C
C	DRAW BOTTOM LINE
C
	XP=XFORM(NX,1,AMIN)
	YP=YFORM(NX,1,AMIN)
	CALL PLOT(XP,YP,3)
	XP=XFORM(NX,NZ,AMIN)
	YP=YFORM(NX,NZ,AMIN)
	CALL PLOT(XP,YP,2)
	XP=XFORM(1,NZ,AMIN)
	YP=YFORM(1,NZ,AMIN)
	CALL PLOT(XP,YP,2)
C
C	PLOT AXIS LABELS
C
71	CONTINUE
	IF (IAXIS.NE.0) THEN		!PLOT AXIS LABELS
		NADD=0
		IF (JF.EQ.2) THEN
			NADD=100000
			IC(1)=ICOL(1)
			IC(2)=ICOL(2)
			IC(3)=ICOL(3)
			IC(4)=ICOL(4)
		ENDIF
		XP=XFORM(NX,NZ,AMIN)
		YP=YFORM(NX,NZ,AMIN)
		XP1=XFORM(1,NZ,AMIN)
		YP1=YFORM(1,NZ,AMIN)
		ANG=ATAN2(YP-YP1,XP-XP1)*180./TPI
		ZLEN1=SQRT((XP-XP1)**2+(YP-YP1)**2)
		IF (NXT.GT.0) THEN	! PLOT X AXIS
			IF (IAFF.EQ.1) THEN
			  CALL AXIS3(XP1,YP1,XT,-NADD-NXT,ZLEN1,
     $					ANG,XASTART,XAEND,TX,
     $					TSX,FDX,IC)
			ELSE
			  VAL1=INT(XLEN+.5)+1.
			  CALL AXIS3(XP1,YP1,XT,-NADD-NXT,ZLEN1,
     $					ANG,XASTART,XAEND,VAL1,
     $					0.15,4.01,IC)
			ENDIF
		ENDIF
		XP1=XFORM(NX,1,AMIN)
		YP1=YFORM(NX,1,AMIN)
		ANG=ATAN2(YP1-YP,XP1-XP)*180./TPI
		ZLEN1=SQRT((XP1-XP)**2+(YP1-YP)**2)
		IF (NZT.GT.0) THEN		! PLOT Z AXIS
			IF (IAFF.EQ.1) THEN
			  CALL AXIS3(XP,YP,ZT,-NADD-NZT,ZLEN1,
     $					ANG,ZAEND,ZASTART,TZ,
     $					TSZ,FDZ,IC)
			ELSE
			  VAL1=INT(ZLEN+.5)+1.
			  CALL AXIS3(XP,YP,ZT,-NADD-NZT,ZLEN1,
     $					ANG,ZAEND,ZASTART,VAL1,
     $					0.15,4.01,IC)
			ENDIF
C
C	PLOT Y AXISES
C
		ENDIF
		DY=1./YSCALE
		XP1=XFORM(NX,NZ,AMAX)
		YP1=YFORM(NX,NZ,AMAX)
		ZLEN1=SQRT((XP1-XP)**2+(YP1-YP)**2)
		IF (NYT.GT.0) THEN 	!PLOT Y AXIS
			XP=XFORM(1,NZ,AMIN)	! LEFT SIDE
			YP=YFORM(1,NZ,AMIN)
			XP1=XFORM(NX,1,AMIN)	! RIGHT SIDE
			YP1=YFORM(NX,1,AMIN)
			IF (IAFF.EQ.1) THEN
			  CALL AXIS3(XP,YP,YT,NADD+NYT,ZLEN1,
     $					90.,AMIN,AMAX,TY,
     $					TSY,FDY,IC)
			  CALL AXIS3(XP1,YP1,YT,-NADD-NYT,ZLEN1,
     $					90.,AMIN,AMAX,TY,
     $					TSY,FDY,IC)
			  N1=INT(TY)	! MAJOR AXIS TICKS
			ELSE
			  VAL1=INT(YLEN+.5)+1.
			  CALL AXIS3(XP,YP,YT,NADD+NYT,ZLEN1,
     $				90.,AMIN,AMAX,VAL1,0.15,4.01,IC)
			  CALL AXIS3(XP1,YP1,YT,-NADD-NYT,ZLEN1,
     $				90.,AMIN,AMAX,VAL1,0.15,4.01,IC)
			  N1=IFIX(YLEN+.5)+1
			ENDIF
C
C	PLOT BACK PANEL
C
			IF (IAF.EQ.0) THEN
		IF (JF.EQ.2) CALL PLOT(FLOAT(ICOL(5)),0.,0)
				DO 4338 K=1,N1
				 VAL1=(K-1)*DY+AMIN
				 W2(NW)=XFORM(1,NZ,AMIN)
				 W2(1+NW)=YFORM(1,NZ,AMIN)
				 W2(2+NW)=XFORM(1,NZ,VAL1)
				 W2(3+NW)=YFORM(1,NZ,VAL1)
				 W2(4+NW)=XFORM(1,1,VAL1)
				 W2(5+NW)=YFORM(1,1,VAL1)
				 W2(6+NW)=XFORM(1,1,AMIN)
				 W2(7+NW)=YFORM(1,1,AMIN)
			CALL NXTVU(2,W2(NW),4,W2,NW2D,IERR)
				 IF (IERR.NE.0) GOTO 42
				 W2(NW)=XFORM(1,1,VAL1)
				 W2(1+NW)=YFORM(1,1,VAL1)
				 W2(2+NW)=XFORM(NX,1,VAL1)
				 W2(3+NW)=YFORM(NX,1,VAL1)
				 W2(4+NW)=XFORM(NX,1,AMIN)
				 W2(5+NW)=YFORM(NX,1,AMIN)
			CALL NXTVU(2,W2(NW),3,W2,NW2D,IERR)
				 IF (IERR.NE.0) GOTO 42
4338				CONTINUE
			ENDIF
		ENDIF
	ENDIF
C
C	FINISH UP
C
	CALL PLOT(0.,0.,3)			!PEN UP
	IF (IFLAG.GT.0) THEN
		CALL CTERM(2)			!CLEAR TERMINAL
		CALL PLOTND			!CLOSE PLOT OUTPUT
		REPEAT=.FALSE.
	ENDIF
	IF (IFLAG.LT.0) THEN
		REPEAT=.TRUE.
		CALL CTERM(1)			!PUT TERMINAL IN TEXT MODE
	ENDIF
	RETURN
	END
